CurrentCell.MoveTo

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!

5 Replies

AD Administrator Syncfusion Team September 26, 2006 08:45 AM UTC

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


AD Administrator Syncfusion Team September 26, 2006 09:22 AM UTC

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 !


AD Administrator Syncfusion Team September 26, 2006 03:08 PM UTC

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


AD Administrator Syncfusion Team September 27, 2006 11:04 AM UTC

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


AD Administrator Syncfusion Team September 27, 2006 03:43 PM UTC

Hello Haneef,

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

Regards,


Loader.
Up arrow icon