2

Is it possible to have a horizontal columns in DataGridView, with ability to bind those columns?

5
  • Not very satisfactorily, it seems. See stackoverflow.com/questions/853663/…
    – StuartLC
    Nov 27, 2012 at 8:34
  • That solution doesn't suit me. I was wondering about some kind of solution that will support binding. It seems that there are no easy ones=(
    – dmigo
    Nov 27, 2012 at 8:46
  • 1
    you need to just pivot the query which is fetching the results. Pivot is a keyword which will convert columns into rows and vice-versa. Nov 27, 2012 at 9:11
  • @MARKAND Bhatt by query do you mean SQL query or LINQ?
    – dmigo
    Nov 27, 2012 at 15:23
  • In sql server. Take a look at this link blog.sqlauthority.com/2008/06/07/… Nov 28, 2012 at 9:15

1 Answer 1

1

You dont have to Flip the DataGridView instead Flip the DataSet to bind

Try this:

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;
}

For more details visit Displaying-Vertical-Rows-in-DataGrid-View

1
  • That's not exactly what I was looking for, since it doesn't support binding.
    – dmigo
    Nov 27, 2012 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.