DataGrid Control...

GForce
04-07-2006, 08:39 AM
I am working with a Read-Only DataGrid Control and it is giving me fits. I just want the User to select a Record from a Table using Sorting and Filtering capabilities rapidly available to DataViews and DataGrids. I therefore select the set dgTable.Select(dgTable.CurrentRowIndex) in the CurrentCellChanged Event.
The problem is that the control paints the Cell as if it were active for editing, despite the fact that the ReadOnly Property is set to True. Therefore I get a nice solid Blue Record Hightlight, interrupted by Grey/Brown Cell Active for Editing indication. Though it will not allow me to update the cell, at least that much is correct. See the attached JPEG for the Ugly user Interface...
I am new to .NET, but I have tried all the Properties I can think of, please make suggestions...

torpkevuk
04-07-2006, 11:05 AM
If im understanding you correctly, you want to select the row (and know which row they click) by clicking on any cell in that row?

If thats the case, this code should do it for you.


Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
Dim pt = New Point(e.X, e.Y)
Dim hit As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)
If hit.Type = Windows.Forms.DataGrid.HitTestType.Cell Then
DataGrid1.CurrentCell = New DataGridCell(hit.Row, hit.Column)
DataGrid1.Select(hit.Row)
End If
MsgBox(DataGrid1.CurrentRowIndex)
End Sub


Obviously, change DataGrid1 for the name of your datagrid

Hope that helps

GForce
04-07-2006, 11:58 AM
Thanks... Not sure why the User Interface draws properly when you jump through hoops determining where the Mouse Pointer was within the Control when the Button was Pressed, but it does work. My original solution of DataGrid1.Select(DataGrid1.CurrentRowIndex) should have accomplished the same thing, but obviously there was a timing issue involved. It almost seems that the DataGrid is the old MSGrid Control which we used to have to chase a TextBox Control around the interior to allow Editing.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum