Hello:
Can you insert new rows on top of the grid? What I would like to do is basically to set the data source to be a DataTable and be able afterwards to insert rows/col on top of the first row. Is this possible? If not what would be a sensiblie approach to achieve this?
Thanks,
Mihail
If you are using a datatable as your datasource and you don't have any special sorting happening you can simply insert your record at the top of your datatable.
datatable.rows.insert(rowToAdd,0)
Brandon
Actually, I don't think this works. You can call Insert on the data table and it wil insert the row at the position you specify. But when the DataTable fires the ListChanged notification, it does not pass in the correct index of the newly-added item, it always passes in the last index of the list, so the row will appear in the grid at the bottom.
One thing you could do, though, is use the grid.Rows.Move method to move the row after it is added.
In this case I should even bothter with Insert right? Adding them and moving them afterwards will be good enough.
All these rows (6 at this time) that I want to insert above the first row will be use to set column headers for whatever the grid shows after plugging in the DataTabe as a data source. Each column of these rows will have combo boxes or some other controls on it. I wonder if I can use Groups and headers in this case? If I can will be able to make the headers be a combo box or any other control? I assume that if I just add the rows and move them afterwards I will be able to do this without problems. Thanks!
Combo1
Combo2
Combo3
Combo11
Combo22
Combo33
Combo111
Combo222
Combo333
DataTable Column A
DataTable Column B
DataTable Column C
Hm, I'm not sure I understand the question. A column header can't have a dropdown in it. So if these cells are going to have dropdowns, then they need to be actual cells, you can't use a columnor group header. Unless you want to try to position a combobox control over the header or something like that.
Mike:
I thought that I can have drop down in a column header, obviously not. The top 5 rows that I need to insert and the combination of combo boxes/text that I need to add for each cell of these rows will dictate the specific column behavior for transfer/save in a DB, in a way a multiple column headers for lack of better terms. They are not part of the data but I still want to use the data table as a data source instead of loading the grid row by row. So I need a way to use a data source and be able to insert rows that will act as multiple column headers for the grid. Hope that I clarify a bit what I need to do.
Hi Mihail,
Well, it sounds like you could use Fixed Rows for this.These rows would have to be part of the data source, though. There's no such thing as an unbound row.
I don't know of any samples of this. But it sounds like what you want to do here is add a row to the grid and set the Fixed property of the row to true.
Thank Mike, i will give it a try. Any chance of an example somewhere of a grid with multiple column rows/headers (bound or unbound).