mutiple row types in datagridview

Is it possible to have 2 types of rows in a datagridview.
e.g. an orderheader with orderdetails
rowtype1   order  customername    date
rowtype2   article# article name     price  number ordered
rowtype2   article# article name     price  number ordered
rowtype2  article# article name      price  number ordered  
rowtype1  order  customername    date
rowtype2   article# article name     price  number ordered
rowtype2   article# article name     price  number ordered
as you can see rowtype1 has an other number of columns as rowtype2
Who is Participating?
oobaylyConnect With a Mentor Commented:
You can't do that as the each column in the DataGridView has a DataPropertyName which tells the column where it should get it's data to display.
In your example your two different row types have different names (and different data types from the looks of it), so the columns would have some issues knowing which column mapping to use.

You could create a dataable with the total number of columns required, all with a datatype of object. You could then populate the table with whatever data you need on a per-row basis. There would be two issues with this however:
  1. You lose any type safety if you're using the grid to edit the data displayed
  2. You won't be able to do any custom formatting on the columns: How would the 3rd column know to format a value as a DateTime or Decimal?
If you're just displaying data (ie. the grid is readonly), you could create a table only containing string values, and then as you populate it, format each value the way you desire. I've done this to display a bank statement type display.

If you're wanting to edit the data, I'd recommend going with two grids, the top one showing the Order Number, Customer Name & Date. The lower one is refreshed when selecting a different order, and shows Article info, Price & Quantity
Bob LearnedConnect With a Mentor Commented:
That looks like a perfect opportunity to use the banding technology with the Infragistics UltraWinGrid/UltraWebGrid...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.