Adding rows to the middle of a datagrid.

  • Thread starter Thread starter ChrisM
  • Start date Start date
C

ChrisM

Hi all,

I have an application which has a Windows Form which displays information in
a DataGrid control.
I'm trying to find a way to allow the user to insert a row in the middle of
the grid.
Does anyone know how(if) this can be done?

Thanks,

ChrisM
 
ChrisM,

Technically, you shouldn't be concerned with the position of the rows in
the DataTable itself. If you need ordering on the data that you have in the
table, then you should have a DataView on the DataTable which is ordered the
way that you need it to be.

Once you have that, when you add a row, you can set the value in the
column that is sorted on to a value that will place the row in the
appropriate position when ordered on that column. You don't have to add the
column to the server, but rather, you can just add the column after you get
the structure from your data layer.

Hope this helps.
 
Thank You Nicholas,

That was just the nudge that I needed. My DataGrid was already based on a
DataView, rather than a DataTable. I just hadn't quite got my head around
using the DataView.Sort, but it works now (at least in prototype)

Thanks again,

ChrisM
 
Back
Top