Insert row in table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Inserting a row into a table (table.InsertAt(row, in)) results in that row being shown last in data grid. I cant see a (straightforward) way of having DataGridTableStyle show it where it is (in the table). in other words, if I have 4 rows and call table.InsertAt(row, 2) I woud like an empty row to show 3rd, not last

Also, there seems to be no (obvious) way of forcing DataGridTableStyle to rebuild itself from model (and that way present rows in the order they show in the table)

Any suggestions would be more than appreciated

Regards All,
 
The location specified by InsertAt is reflected by the order of rows in the
DataRowCollection only. If more than one row is returned in a DataRow array,
the inserted row may not be returned in the location specified by InsertAt.
For example, the Rows property returns the row in the specified insert
position. Select and GetChildRows may not. When you write the contents of
the DataRowCollection as XML (for example, WriteXml), the rows are written
according to the order specified by the DataRowCollection.

Ernest


boble said:
Inserting a row into a table (table.InsertAt(row, in)) results in that row
being shown last in data grid. I cant see a (straightforward) way of having
DataGridTableStyle show it where it is (in the table). in other words, if I
have 4 rows and call table.InsertAt(row, 2) I woud like an empty row to show
3rd, not last.
Also, there seems to be no (obvious) way of forcing DataGridTableStyle to
rebuild itself from model (and that way present rows in the order they show
in the table).
 
If it were a solution to my problem, I would have solved it hours ago ...

The MSDN says that InsertAt could not be a solution to your problem. I think
this is an answer, that is: there is nothing wrong in the way you use the
InsertAt, but simply it cannot do what you expect it does. In other words,
it makes no much sense insisting in solving this matter using InsertAt, but
find alternatives like moving the rows in other DataTable object in the
order you like.

row=dtSource.Rows[5];
dtSource.Rows.Remove(row)

dtDest.Rows.Add(row)

This way you move just references of the rows(not the data) , so it wouldn't
take much time to execute.

Ernest




boble said:
Thank you Ernest for posting a copy of paragraph from MSDN:) ... If it
were a solution to my problem, I would have solved it hours ago ...
 
Try using datatable1.Rows.InsertAt, and then call dataTable1.AcceptChanges.

DataRow rowBlank = datatable1.NewRow();
rowBlank["TokenTypeID"] = 0; //set some values
datatable1.Rows.InsertAt(rowBlank, rowIndex);
rowBlank.AcceptChanges();
datatable1.AcceptChanges();

====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

boble said:
Inserting a row into a table (table.InsertAt(row, in)) results in that row
being shown last in data grid. I cant see a (straightforward) way of having
DataGridTableStyle show it where it is (in the table). in other words, if I
have 4 rows and call table.InsertAt(row, 2) I woud like an empty row to show
3rd, not last.
Also, there seems to be no (obvious) way of forcing DataGridTableStyle to
rebuild itself from model (and that way present rows in the order they show
in the table).
 
Back
Top