Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Rows.InsertAt behavior

Status
Not open for further replies.

JasonDBurke

Programmer
Jun 20, 2001
54
0
0
US
Hello,
I'm attempting to insert new row data into a DataTable using the InsertAt method. What I want to do is have the new rows always appear first in the datagrid. When I stick this code behind a button and click repeatedly it works, however when I have this same code in a thread it does not insert correctly - it appends. Does it have anything to do with after the button click event is resolved somehow the datagrid is being reset as opposed to the code being in a thread? Below is the code.


DataRow myDataRow = myDataTable.NewRow();

myDataRow["Alert"] = "alert";

myDataTable.Rows.InsertAt(myDataRow,0);

dataGrid1.DataSource = myDataTable;

Thanks,
Jason
 
check on that last message..

That code is actually always appending. Even with a button click so there must be something I'm missing.
 
This code works..notice the AcceptChanges().. <-- that did it

DataRow myDataRow = myDataTable.NewRow();

myDataRow["Alert"] = "alert" + System.DateTime.Now.ToString();

myDataSet.Tables[0].Rows.InsertAt(myDataRow,0);

myDataSet.Tables[0].AcceptChanges();

dataGrid1.DataSource = myDataSet.Tables[0].DefaultView;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top