views:

136

answers:

3

I have a DataGridView that's bound to a DataSet. It has columns DateCreated, Weight, DateUsed. Those three columns do not take up much horizontal space on DataGridView that is nearly full screen. Is it possible to have those columns wrap back to the top if the view is wide enough to support a second group of those colums. So across the header it would read DateCreated, Weight, DateUsed, DateCreated, Weight, DateUsed. Then when a row is clicked, only 3 cells would be highlighted, not all six. Is there something that can provide this functionality?

A: 

Quite difficult to understand what exactly you mean but I am certain it can be done with somekind of JS functionality, where you compute the width of columns and width of browser/screen and adjust DataGridView accordingly. You could have few problems setting "td" cell widths , so changing to CSS providers and render as div's and span's could be an option.

mare
This is not a web app, just your standard run of the mill Windows Forms app.
Wesley
A: 

Might be cheesy but just stick two DGVs side by side, turn the left DGV's vertical scrollbar off, bind each DGV with half of the data, and control them both with the right DGV's scrollbar.

Aside from that I'm thinking you'll need a fair bit of coding to get a single DGV to do what you want.

John at CashCommons
+1  A: 

I don't know of anything like that out of the box.

You could create that effect yourself. You would need to decouple the actual data from the presentation of the data. Instead of a single DataRow per grid row, you'll need to merge them together to show multiple rows on a single row.

So your helper method might do the following:

  • Compare the width of the DataGridView to the number of rows
  • Determine how many DataRows columns would be visible
  • Build a new DataTable with extra column sets to represent each column
    • Example: DateCreated1, Weight1, DateUsed1, DateCreated2, Weight2, DateUsed2, etc.
  • Populate the DataTable with the original DataSet
  • Bind the DataGridView to the new table

Some considerations: can users sort the data? If so, you'll have to write that yourself.

Do you need to be able to add new rows using this view? That sounds very difficult with this kind of view.

Paul Williams
No, users can't sort, add or delete rows. Thanks for your input. Although not exactly what I'm looking for, this seems to be the way I'm going to have to go.
Wesley