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

Setting the CurrentCell of a GridDataboundGrid

Hello,

I'm having a problem setting the CurrentCell of my griddataboundgrid. I've searched a while, but i didn't found a solution yet. When a new record is added, i want the CurrentCell to be activated on that new record in the grid. I'm working with a datatable and i'm setting the datasource of my grid to that datatable. I allready tried getting the rowindex of my datatable, then rowindextoposition and then moving the currentcell by following code:

rowindex = datatabel.DefaultView.Table.Rows.IndexOf(newrow);
gridposition = this.grid.Binder.RowIndexToPosition(rowindex);
this.grid.CurrentCell.MoveTo(rowindex, 0);

But the grid is activating the wrong record.
I'm sorting the datatable as well, but i don't think that's the problem.

Someone has a solution for me?

Thanks in advance,
Gunther


5 Replies

NA Nisha Arockiya A Syncfusion Team December 4, 2008 12:19 PM UTC

Hi Gunther,

We appreciate your interest in Syncfusion products.

This can be achieved by the folowing modified code snippets:

int rowindex = dt.Rows.IndexOf(dr);
this.gridDataBoundGrid1.CurrentCell.MoveTo(rowindex +1, 0);

Please refer the sample:

http://websamples.syncfusion.com/samples/Grid.Windows/Grid_WG_GDBGCurrentCellMoveto/main.htm

Please try this and let me know if this helps.

Regards,
Nisha



AD Administrator Syncfusion Team December 5, 2008 10:16 AM UTC

Hi Nisha,

Thanks for your reply,

The CurrentCell option works, but it's activating the wrong record. I think the problem is duo to my sorting(in my main form), is that possible?

I'm sorting with datatable.DefaultView.Sort = "Code ASC". Is it possible that add a record in a sorted grid (datatable.DefaultView.Sort)?

Thanks,
Gunther

>Hi Gunther,

We appreciate your interest in Syncfusion products.

This can be achieved by the folowing modified code snippets:

int rowindex = dt.Rows.IndexOf(dr);
this.gridDataBoundGrid1.CurrentCell.MoveTo(rowindex +1, 0);

Please refer the sample:

http://websamples.syncfusion.com/samples/Grid.Windows/Grid_WG_GDBGCurrentCellMoveto/main.htm

Please try this and let me know if this helps.

Regards,
Nisha





NA Nisha Arockiya A Syncfusion Team December 8, 2008 08:44 AM UTC

Hi Gunther,

Thanks for th Updates.

Please try the code below in the CurrentCellValidating event handler, this will help you.

void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
GridBoundRecordState rs = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(cc.RowIndex);
int pos = rs.Position;
CurrencyManager cm = rs.ListManager as CurrencyManager;
if (cm != null)
{
DataRowView drv = (DataRowView)cm.Current;
DataRow dr = (DataRow)drv.Row;
Console.WriteLine(dr[0].ToString());
Console.WriteLine("Current Position: {0}", cm.Position);
}
}


Let me know if you have any other questions.
Regards,
Nisha



AD Administrator Syncfusion Team December 8, 2008 03:12 PM UTC

Hi Nisha,

Thanks for your reply.

I tried your solution, but the problem wasn't the fact that i couldn't get my newrow data, but it was duo to my sorting that my rowindex (of the newrow) was incorrect. I googled a while and found a solution:

rowindex = datatabel.DefaultView.Table.Rows.IndexOf(newrow);
int roIdx = datatabel.DefaultView.Find(nieuwerij["Code"]);
this.grid.CurrentCell.MoveTo(roIdx + 1, 0);

Though i would like to thank you for your help!

>Hi Gunther,

Thanks for th Updates.

Please try the code below in the CurrentCellValidating event handler, this will help you.

void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
GridBoundRecordState rs = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(cc.RowIndex);
int pos = rs.Position;
CurrencyManager cm = rs.ListManager as CurrencyManager;
if (cm != null)
{
DataRowView drv = (DataRowView)cm.Current;
DataRow dr = (DataRow)drv.Row;
Console.WriteLine(dr[0].ToString());
Console.WriteLine("Current Position: {0}", cm.Position);
}
}


Let me know if you have any other questions.
Regards,
Nisha





NA Nisha Arockiya A Syncfusion Team December 9, 2008 12:15 PM UTC

Hi Gunther,

Glad that you have got the problem solved.Thanks for sharing information with us.

Please let us know any other concerns.

Again thanks for using Syncfusion Products.
Regards,
Nisha


Loader.
Live Chat Icon For mobile
Up arrow icon