【问题标题】:DataGridView with horizontal columns具有水平列的 DataGridView
【发布时间】:2012-11-27 08:32:06
【问题描述】:

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

【问题讨论】:

  • 似乎不太令人满意。见stackoverflow.com/questions/853663/…
  • 那个解决方案不适合我。我想知道某种支持绑定的解决方案。好像没有容易的=(
  • 您只需要旋转获取结果的查询即可。 Pivot 是将列转换为行的关键字,反之亦然。
  • @MARKAND Bhatt 的查询是指 SQL 查询还是 LINQ?
  • 在 sql server 中。看看这个链接blog.sqlauthority.com/2008/06/07/…

标签: c# winforms datagridview


【解决方案1】:

您不必翻转 DataGridView 而不是 翻转 DataSet 以进行绑定

试试这个:

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

【讨论】:

  • 这不是我想要的,因为它不支持绑定。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
  • 2010-11-05
  • 2016-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多