private void item_grid_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex==taxone_col_index || e.ColumnIndex==taxtwo_col_index)
{
}
}
private void item_grid_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
item_grid.CellClick; // i did this but its not working }
}
i want to perform the cell click event from keypress event. how to do it?
It sounds like what you want is to know the row and column index of the cell that the key is pressed in. From that you will then be able to look up the value of the cell.
To do this just use the
CurrentCellproperty of theDataGridView.Trying to artificially create a
CellClickis just asking for trouble.One thing to note is that you will probably need to handle the
EditingControlShowingevent and attach aKeyPresshandler to the underlying editing control since typing into aDataGridViewcell does not raise the grid levelKeyPressevent.If you really want to create a
CellClickevent you will need to subclass theDataGridViewcontrol, and create your ownRaiseCellClick()method which then calls the protectedOnCellClick()method:But even this doesn’t particularly help you since the
DataGridViewCellEventArgsneeds to take the row and column indexes in its constructor.