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.

CurrentCell.MoveTo

Thread ID:

Created:

Updated:

Platform:

Replies:

49720 Sep 25,2006 11:24 AM Sep 27,2006 11:43 AM Windows Forms 5
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 25, 2006 11:24 AM

Hello,

I have a bound grid and I want to move the current cell. When I have combo box cell and I want to make this cell as current cell the grid.CurrentCell.MoveTo returns false. This is my code
grid.ForceCurrentCellMoveTo = true;
bool movedResult = grid.CurrentCell.MoveTo(e.RowIndex, colIndex, GridSetCurrentCellOptions.SetFocus);
grid.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.AlwaysVisible;

This code is used inside a rowsaved event handler and is used for row validation (when a column is null alert the user and make this cell as current cell). With normal columns (text column) works properly.

Could you please give me an simple idea where I am wrong ?

Thanks a lot !

Regards!

Administrator [Syncfusion]
Replied On September 26, 2006 04:45 AM

Hi Venatir,

To validate a row in a the grid, you need to use the RowSaved,RowLeave and CurrentCellMoving event and set ( e.Cancel = TRUE) to handle the event. Below is a code snippet in RowSaved event.

private void GridRowSaved(object sender, Syncfusion.Windows.Forms.Grid.GridRowEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = grid.CurrentCell;

object obj = grid.Model[e.RowIndex,3].CellValue;
if( obj == null || obj.ToString() == string.Empty)
{
//Set the ( e.Cancel = TRUE ) to cancel the RowSaved event.
e.Cancel = true;

MessageBox.Show("Invalid value in combo cell");
//To check the state of moving
if(!cc.IsInMoveTo )
{
cc.MoveTo(cc.RowIndex,3);
}
}
}


If I did not answer your question, please explain a little more about what you want, and I’ll try again.

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On September 26, 2006 05:22 AM

Hello Haneef,

First of all thnaks for your help. Please take a look at my code :

private void grid_RowSaved(object sender, GridRowEventArgs e)
{
bool hasEncounterError = false;
string err = null;

try
{
err = validateRow(dtGrid.DefaultView[e.RowIndex - 1].Row);
if (err != null)
{
hasEncounterError = true;
e.Cancel = true;

string message = res.getString("msg_invalidDataRC");
GUIUtils.showWarning(GUIUtils.ApplicationForm, message);
if (!grid.CurrentCell.IsInMoveTo)
{
bool movedResult = grid.CurrentCell.MoveTo(e.RowIndex, colIndex, GridSetCurrentCellOptions.SetFocus);
}
grid.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.AlwaysVisible;
return;
}


//saving functions
}

It seems that you sent to me ... but unfortunately always IsInMoveTo = true. I don''t know what happens.

Thanks again for your help !

Administrator [Syncfusion]
Replied On September 26, 2006 11:08 AM

Hello,

Please take a look at this simple example that I''ve attached. It create a data table with 3 integer columns and binded to the grid. Please modify a column2 or column3 and in RowSaved event must move to the first column (it''s hardcoded). But it doesn''t work. :((

Thanks a lot !

TestDBGrid.zip

Administrator [Syncfusion]
Replied On September 27, 2006 07:04 AM

Hi,

Try the below code to move the currentcell to the specified colindex in a grid ( same CurrentRowIndex).

public void MoveToColumn(object sender, int ColIndex)
{
GridDataBoundGrid gc = sender as GridDataBoundGrid;
int noOfMoves = gc.CurrentCell.ColIndex - ColIndex;

string KeyValue = "Left";

if (gc.CurrentCell.IsEditing)
SendKeys.Send("{Home}");

if (noOfMoves < 0)
{
KeyValue = "Right";
noOfMoves *= -1;

if (gc.CurrentCell.IsEditing)
SendKeys.Send("{End}");
}

for (int i = 0; i < noOfMoves; i++)
SendKeys.Send("{" + KeyValue + "}");
}

You can call this method using the code.

//RowSaved Event.
MoveToColumn(sender, 2);

Here is a modifed sample.
http://www.syncfusion.com/Support/user/uploads/ModifiedTestDBGrid_20b997df.zip

Thanks,
Haneef

Administrator [Syncfusion]
Replied On September 27, 2006 11:43 AM

Hello Haneef,

Thank you very much for your help. Works very well!

Regards,


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.

;