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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

new record and selection

Thread ID:

Created:

Updated:

Platform:

Replies:

7320 Sep 19,2003 11:12 AM UTC Sep 20,2003 06:07 AM UTC Windows Forms 4
loading
Tags: GridControl
sahon
Asked On September 19, 2003 11:12 AM UTC

I'm adding new record in DataTable by my program - not internally in the grid. This table is as DataSource for a Grid. How can I find index of newly added row and select this record in a Grid? Thank you

Administrator [Syncfusion]
Replied On September 19, 2003 03:13 PM UTC

If you have grid.EnableAddNew = false, then teh last row will be grid.model.RowCount. So, you could try: grid.CurrentCell.MoveTo(grid.model.RowCount, 1); If this does not work, then also call grid.Focus() and set grid.ForceCurrentCellMoveTo = true; to see if that handles it. If you have EnableAddNew = true, then the row should be one less than the RowCount.

sahon
Replied On September 20, 2003 04:14 AM UTC

it doesn't work with sorting in my grid > If you have grid.EnableAddNew = false, then teh last row will be grid.model.RowCount. So, you could try: > > grid.CurrentCell.MoveTo(grid.model.RowCount, 1); > > > If this does not work, then also call grid.Focus() and set grid.ForceCurrentCellMoveTo = true; to see if that handles it. > > If you have EnableAddNew = true, then the row should be one less than the RowCount.

Administrator [Syncfusion]
Replied On September 20, 2003 05:39 AM UTC

If you are sorting, then you will have to find the new row in the sorted grid. If your grid displays a primary key column, you can use that key and the grid's support for Find to locate the row. If you do not have a primary key, then you could still use this method, but the located row may not be the new one. Attached is a lttle sample. Another way you can do this that will work for any IBindingList DataSource whether or not there is a primary key, is to use the IBindingList.ListChanged event. In the sample, if you replace the button_click code and add a ListChanged handler as below, that will also position the current cell.
private void cm_ListChanged(object sender, ListChangedEventArgs e)
{
	if(e.ListChangedType == ListChangedType.ItemAdded)
	{
		Console.WriteLine(e.NewIndex);
		this.gridDataBoundGrid1.Focus();
		this.gridDataBoundGrid1.CurrentCell.MoveTo(e.NewIndex+1,1);  
}

private void button1_Click(object sender, System.EventArgs e)
{
	CurrencyManager cm = (CurrencyManager)this.BindingContext[dt];
	((IBindingList)cm.List).ListChanged += new ListChangedEventHandler(cm_ListChanged);

	DataRow dr = dt.NewRow();
	dt.Rows.Add(dr);

	((IBindingList)cm.List).ListChanged -= new ListChangedEventHandler(cm_ListChanged);
}

sahon
Replied On September 20, 2003 06:07 AM UTC

works perfectly, thank you

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;