Select row of Datagrid, and disable single cell selection.

G

Guest

Hey,
Having somewhat of an issue, I have a datagrid which is giving me issues.
The Datagrid is setup for the user to double click the row, the row is
selected and data within that row populates a form for editing. the problem
is when a user clicks on a cell instead of the whole row, I get an error. My
question is this, is there anyway I can setup the datagrid so when the user
clicks on any cell, the whole row is selected not just that cell. I have set
the datagrid.Readonly=true. Any help would be appreciated.
Thank you,
Terry
 
C

Chris, Master of All Things Insignificant

I converted this on the fly for C# so it hasn't been tested. Put this into
your mouseup or mousedown event on the datagrid. You may also want to test
for hits on HitTestType.RowHeader. Also think about if they use the arrow
keys to move. You may need to dig deeper to get full functionality but
HitTestInfo is the key.

Dim pt as System.Drawing.Point = new System.Drawing.Point (e.X, e.Y)
dim hit as DataGrid.HitTestInfo= DG.HitTest(pt)
if hit.Type == DataGrid.HitTestType.Cell then
DG.CurrentCell = new DataGridCell(hit.Row, hit.Column)
DG.Select(hit.Row)
End If

Hope this helps.
Chris
 
G

Guest

Chris,
Transformed this to C# and this worked! As we say here in our IT
Department, "Your The Best!"
Thanks again!
Terry
c# version:
System.Drawing.Point pt = new System.Drawing.Point (e.X,e.Y);
DataGrid.HitTestInfo hit = dgClientRequest.HitTest(pt);
if(hit.Type == DataGrid.HitTestType.Cell)
{
dgClientRequest.CurrentCell = new DataGridCell(hit.Row, hit.Column);
dgClientRequest.Select(hit.Row);
}
 
C

Chris, Master of All Things Insignificant

LOL, I transformed it out of C# to post it. I'm so use to posting in the VB
group I thought I had to get it into VB for you. At least you got it
working. Do you need to make this work with the Arrow Keys? I was thinking
about it more and might have an easy way to do it.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top