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.

Setting the CurrentCell of a GridDataboundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

77818 Nov 18,2008 07:10 AM Dec 9,2008 07:15 AM Windows Forms 5
loading
Tags: GridControl
Gunther Devisch
Asked On November 18, 2008 07:10 AM

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


Nisha Arockiya A [Syncfusion]
Replied On December 4, 2008 07:19 AM

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


Administrator [Syncfusion]
Replied On December 5, 2008 05:16 AM

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




Nisha Arockiya A [Syncfusion]
Replied On December 8, 2008 03:44 AM

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


Administrator [Syncfusion]
Replied On December 8, 2008 10:12 AM

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




Nisha Arockiya A [Syncfusion]
Replied On December 9, 2008 07:15 AM

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


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.

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.

;