Datagrid cell - How to de-select a cell

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello,
Can someone tell me how you de-select (un select) the currently selected
cell in a datagrid?
Thanks
 
I've tried dataGrid.Unselect(row), I've tried setting the Focus() to another
control, I ve tried dataGrid.Select(row) to select another row...nothing
unselects the currently selected cell. Can someone please assist?
Thanks
 
Hi Randy,

Thanks for posting in this group.
If you want to de-select current selected row, you can use UnSelect method:
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(dataGrid1.CurrentRowIndex.ToString());
dataGrid1.UnSelect(dataGrid1.CurrentRowIndex);
}

If you want to change the current cursor focus to another cell, you can set
DataGrid's CurrentCell property.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks Jeffrey,
There must be some other Window thing going on...I've tried both of these
and no luck...the same cell stays selected. I'll keep plugging along. Thanks
for your help.
 
Oh, one last question...I have the UnSelect in the MouseDown event...right
before leaving this function. Is there another place this should go? Maybe
I've got it in the wrong area and something is stepping on it?
Thanks

Randy said:
Thanks Jeffrey,
There must be some other Window thing going on...I've tried both of these
and no luck...the same cell stays selected. I'll keep plugging along. Thanks
for your help.


"Jeffrey Tan[MSFT]" said:
Hi Randy,

Thanks for posting in this group.
If you want to de-select current selected row, you can use UnSelect method:
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(dataGrid1.CurrentRowIndex.ToString());
dataGrid1.UnSelect(dataGrid1.CurrentRowIndex);
}

If you want to change the current cursor focus to another cell, you can set
DataGrid's CurrentCell property.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Randy,

Thanks for your feedback.
Oh, I think the problem should be the time you invoke UnSelect and set
CurrentCell property.
If you change the selected row or selected cell in MouseDown event, the
mouse will reselect you clicked row or cell. So it appears that your code
has no effect.
I think you should add your code in MouseUp event, do like this:

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
dataGrid1.CurrentCell= new DataGridCell(0,0); //set the selected cell to
first cell
}

or

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
dataGrid1.UnSelect(dataGrid1.CurrentRowIndex);
}

If you still have anything unclear, please feel free to tell me.

Btw: Have good year beginning!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top