Source Grid cell Focus Problem
-
Hi ppl Pls help me with a cell change problem. I have a sourcegrid with 4 column ans 4 rows. I can Insert data to every cell but the problem is I dont wanna use mouse or Tab to change cell. I want to use Enter key to change cell. That mease I will insert data to a cell and press Enter key and coursor will go to next cell. Can anyone have face this problem.... please help me Thanks
-
Hi ppl Pls help me with a cell change problem. I have a sourcegrid with 4 column ans 4 rows. I can Insert data to every cell but the problem is I dont wanna use mouse or Tab to change cell. I want to use Enter key to change cell. That mease I will insert data to a cell and press Enter key and coursor will go to next cell. Can anyone have face this problem.... please help me Thanks
SourceGrid - Open Source C# Grid Control[^] I presume that^ is the source grid you're on about. Something like this should work
void grid1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (grid1.FocusCell.Row == grid1.RowsCount-1)
//to check if you have reached the last cell in the column
{
if (grid1.FocusCell.Column == grid1.Columns.Count - 1)//checks if you have reached the
//last row in the last column
{
grid1[1,0].Focus(); selects the first cell
}
else grid1[1, grid1.FocusCell.Column + 1].Focus();selects the first cell in the next
//column
}
else grid1[grid1.FocusCell.Row + 1, grid1.FocusCell.Column].Focus();//selects the next cell
}
} -
SourceGrid - Open Source C# Grid Control[^] I presume that^ is the source grid you're on about. Something like this should work
void grid1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (grid1.FocusCell.Row == grid1.RowsCount-1)
//to check if you have reached the last cell in the column
{
if (grid1.FocusCell.Column == grid1.Columns.Count - 1)//checks if you have reached the
//last row in the last column
{
grid1[1,0].Focus(); selects the first cell
}
else grid1[1, grid1.FocusCell.Column + 1].Focus();selects the first cell in the next
//column
}
else grid1[grid1.FocusCell.Row + 1, grid1.FocusCell.Column].Focus();//selects the next cell
}
}many many thanks. I have tried it but some error I cant understand... void grid1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (grid1.FocusCell.Row == grid1.RowsCount-1) //to check if you have reached the last cell in the column { if (grid1.FocusCell.Column == grid1.Columns.Count - 1)//checks if you have reached the //last row in the last column { grid1[1,0].Focus(); //selects the first cell } else grid1[1, grid1.FocusCell.Column + 1].Focus();//selects the first cell in the next //column } else grid1[grid1.FocusCell.Row + 1, grid1.FocusCell.Column].Focus();//selects the next cell } } The Bold text "grid1.focuscell.row and grid1.focuscell.colume does not have any defination." Cant you fix it pls Thanks
modified on Tuesday, April 14, 2009 10:18 PM
-
many many thanks. I have tried it but some error I cant understand... void grid1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (grid1.FocusCell.Row == grid1.RowsCount-1) //to check if you have reached the last cell in the column { if (grid1.FocusCell.Column == grid1.Columns.Count - 1)//checks if you have reached the //last row in the last column { grid1[1,0].Focus(); //selects the first cell } else grid1[1, grid1.FocusCell.Column + 1].Focus();//selects the first cell in the next //column } else grid1[grid1.FocusCell.Row + 1, grid1.FocusCell.Column].Focus();//selects the next cell } } The Bold text "grid1.focuscell.row and grid1.focuscell.colume does not have any defination." Cant you fix it pls Thanks
modified on Tuesday, April 14, 2009 10:18 PM
-
many many thanks. I have tried it but some error I cant understand... void grid1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (grid1.FocusCell.Row == grid1.RowsCount-1) //to check if you have reached the last cell in the column { if (grid1.FocusCell.Column == grid1.Columns.Count - 1)//checks if you have reached the //last row in the last column { grid1[1,0].Focus(); //selects the first cell } else grid1[1, grid1.FocusCell.Column + 1].Focus();//selects the first cell in the next //column } else grid1[grid1.FocusCell.Row + 1, grid1.FocusCell.Column].Focus();//selects the next cell } } The Bold text "grid1.focuscell.row and grid1.focuscell.colume does not have any defination." Cant you fix it pls Thanks
modified on Tuesday, April 14, 2009 10:18 PM
Sorry that was my fault :^) You must be using version 4; try this way: :-D
void grid1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
int row = grid1.Selection.ActivePosition.Row;
textBox1.Text = row.ToString();
int column = grid1.Selection.ActivePosition.Column;
if (grid1.Selection.ActivePosition.Row == grid1.RowsCount - 1)
//to check if you have reached the last cell in the column
{
if (column == grid1.Columns.Count - 1)//checks if you have reached the last row in the last column
{
grid1.Selection.Focus(new SourceGrid.Position(1, 0), true);//selects the very first cell} else grid1.Selection.Focus(new SourceGrid.Position(1, grid1.Selection.ActivePosition.Column + 1), true);//selects the first cell in the next column } else grid1.Selection.MoveActiveCell(1, 0); } }
-
Sorry that was my fault :^) You must be using version 4; try this way: :-D
void grid1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
int row = grid1.Selection.ActivePosition.Row;
textBox1.Text = row.ToString();
int column = grid1.Selection.ActivePosition.Column;
if (grid1.Selection.ActivePosition.Row == grid1.RowsCount - 1)
//to check if you have reached the last cell in the column
{
if (column == grid1.Columns.Count - 1)//checks if you have reached the last row in the last column
{
grid1.Selection.Focus(new SourceGrid.Position(1, 0), true);//selects the very first cell} else grid1.Selection.Focus(new SourceGrid.Position(1, grid1.Selection.ActivePosition.Column + 1), true);//selects the first cell in the next column } else grid1.Selection.MoveActiveCell(1, 0); } }
Sorry I was out of town.I have tried it but It didnt work. Dont know why. Do I need to use any event handler code to the .Designer.CS page? Like this.grid1.keypress += new ..... pls make it clear. Thanks again
modified on Saturday, April 18, 2009 11:24 AM