gpt4 book ai didi

c# - 具有水平列的 DataGridView

转载 作者:太空宇宙 更新时间:2023-11-03 13:51:28 26 4
gpt4 key购买 nike

是否可以在 DataGridView 中有一个水平列,并能够绑定(bind)这些列?

最佳答案

您不必翻转 DataGridView,而是翻转 DataSet 进行绑定(bind)

试试这个:

public DataSet FlipDataSet(DataSet my_DataSet)
{
DataSet ds = new DataSet();

foreach (DataTable dt in my_DataSet.Tables)
{
DataTable table = new DataTable();

for (int i = 0; i <= dt.Rows.Count; i++)
{ table.Columns.Add(Convert.ToString(i)); }

DataRow r;
for (int k = 0; k < dt.Columns.Count; k++)
{
r = table.NewRow();
r[0] = dt.Columns[k].ToString();
for (int j = 1; j <= dt.Rows.Count; j++)
{ r[j] = dt.Rows[j - 1][k]; }
table.Rows.Add(r);
}
ds.Tables.Add(table);
}

return ds;
}

有关更多详细信息,请访问 Displaying-Vertical-Rows-in-DataGrid-View

关于c# - 具有水平列的 DataGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13580147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com