|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Confusion on Protected OverridesI created a new project with a new form1 and a new datagrid called myDataGrid. I created a simple DataTable and put 5 rows and 5 columns of data into it. I bound the DataTable to the DataGrid. The example at the end of this post is exactly as copied from the vb.net help screen: I put the new myDataGrid Class following the Form1 Class. I can make the code work with a Button Click event, but not the MouseDown event. When I click on a row it is not selected. I don't understand how to connect the MouseDown mouse event to my form1 class to make the connection. How do I properly create an instance of the myDataDrid class? Do I need eventhandler code of some sort in Form1? Do I need a delegate or something to make this example work? Thanks in advance for any help or pointing me in the right direction. Ron Dahl Public Class MyDataGrid Inherits DataGrid ' Override the OnMouseDown event to select the whole row ' when the user clicks anywhere on a row. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs) ' Get the HitTestInfo to return the row and pass ' that value to the IsSelected property of the DataGrid. Dim hit As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y) If hit.Row < 0 Then Return End If If IsSelected(hit.Row) Then UnSelect(hit.Row) Else [Select](hit.Row) End If End Sub End Class Ron Dahl wrote:
Show quoteHide quote > I'm very confused on how the Protected Overrides works. You need to define the datagrid in the Form using the WithEvents keyword.> I created a new project with a new form1 and a new datagrid called > myDataGrid. > I created a simple DataTable and put 5 rows and 5 columns of data into it. > I bound the DataTable to the DataGrid. > > The example at the end of this post is exactly as copied from the vb.net > help screen: > > I put the new myDataGrid Class following the Form1 Class. > I can make the code work with a Button Click event, but not the MouseDown > event. > > When I click on a row it is not selected. > > I don't understand how to connect the MouseDown mouse event to my form1 > class to make the connection. > > How do I properly create an instance of the myDataDrid class? > Do I need eventhandler code of some sort in Form1? > Do I need a delegate or something to make this example work? > > Thanks in advance for any help or pointing me in the right direction. > > Ron Dahl > > > > Public Class MyDataGrid > Inherits DataGrid > > ' Override the OnMouseDown event to select the whole row > ' when the user clicks anywhere on a row. > > Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs) > ' Get the HitTestInfo to return the row and pass > ' that value to the IsSelected property of the DataGrid. > Dim hit As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y) > If hit.Row < 0 Then > Return > End If > If IsSelected(hit.Row) Then > UnSelect(hit.Row) > Else > [Select](hit.Row) > End If > End Sub > End Class > > > If that doesn't fix it, please show us your form1 code. Chris "Ron Dahl" <rd***@ghp.com> wrote in message Does your the program actually get into your overriding routine?news:ueGGPPRSGHA.4384@tk2msftngp13.phx.gbl... > I'm very confused on how the Protected Overrides works. Put a break point in the code where you do the HitTest() call. If /not/, then the Form /isn't/ using your new grid class. Check the Designer-Generated code and make sure the grid on the form is actually defined as /your/ grid class and not just a DataGrid. HTH, Phill W.
Reading Stream After RedirectStandardOutput=True Blocks
I can't find the error here.... Serial Date Stored procedure handling 1 parent record and multiple child recor Loop through columns of all datarows in a dataset my form cannot from from network checking for EOF DataGridView validation to underlying DataSource Problems using HasMorePages with oleDbDatareader Hide some columns of listview |
|||||||||||||||||||||||