We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

No subject

I want to use the rowheader area of a databound grid to indicate rows that have been modified and rows that are new (inserted). The code below works great for the modified rows, but with new rows (inserted via the asterisk on the grid navigation control) I get some weird display artifacts (new row flickering on/off as the datagrid is scrolled). Also, if I insert a new row into the datatable by calling InsertAt and operating directly on the datatable, the rowheader displays "New" where the new row -should- appear, but the new, blank row appears at the bottom of the datagrid. This code is from a control that inherits from GridDataBoundGrid: protected override void OnPrepareViewStyleInfo(Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { base.OnPrepareViewStyleInfo(e); if(e.ColIndex == 0 && e.RowIndex > 0) { int position = Binder.RowIndexToPosition(e.RowIndex); e.Style.CellType = "Header"; if ((DataSource as DataSet).Tables[DataMember].Rows[position].RowState == DataRowState.Modified) { e.Style.Text = "Mod"; e.Style.BackColor = Color.Red; } else if ((DataSource as DataSet).Tables[DataMember].Rows[position].RowState == DataRowState.Added) { e.Style.Text = "New"; e.Style.BackColor = Color.LightGreen; } } } Thanks Andy

1 Reply

Administrator March 26, 2003 11:00 PM UTC

If you use this code, you will get the inserted row displayed in the correct position.
private void button1_Click(object sender, System.EventArgs e)
{
	this.gridDataBoundGrid1.BeginUpdate();
	DataRow dr = dt.NewRow();
	dr[0] = "XXXXX";  //dt is the datatable
	dt.Rows.InsertAt(dr,2);
	dt.AcceptChanges();
			this.gridDataBoundGrid1.EndUpdate();
	this.gridDataBoundGrid1.Refresh();
}
BUT, this will not show your red new row tag because of the dt.AcceptChanges call. But without this call, the new datarow is not position so the grid can see it properly located in the data source. Maybe you can use some other marker to get the red row flags. Maybe save a list of them or something.
Loader.
Live Chat Icon For mobile
Up arrow icon