implementing inherited control re:Ken Tucker - Inherited DataGrid Class

D

Doug Bell

Hi,
Ken thanks for the code for the ConfirmDeleteDataGrid Class.

I understand the concept of inheritance but I am lost as far as implementing
an inherited control ie a DataGrid.

I have created a Class Module using Ken's code (below)

I have an existing datagrid on my form, I am retrieving a dataset from an
SQL DB (Northwind) with 2 datatables.
I have created 2 DataGridTableStyles and added them to my DataGrid and 2
DataViews.

How do I go about making my DataGrid an Inherited DataGrid that will have
the new property from the ConfirmDeleteDataGrid Class

I have hit a brick wall here and have not been able to find any help on MSDN
site.

Thanks for any pointers,

Doug

Public Class ConfirmDeleteDataGrid

Inherits DataGrid

Public Event DeletedRow(ByVal sender As Object, ByVal e As EventArgs)

Private Const WM_KEYDOWN = &H100



Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean

Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)

If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then

If MessageBox.Show("Delete This Row?", "Confirm Delete", _

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

Return MyBase.PreProcessMessage(msg)

End Function

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean

Dim pt As Point

Dim hti As DataGrid.HitTestInfo

pt = Me.PointToClient(Cursor.Position)

hti = Me.HitTest(pt)

If keyData = Keys.Delete Then

If hti.Type = Me.HitTestType.RowHeader Then

If MessageBox.Show("Delete this row?", "Confirm Delete", _

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

End If

Return MyBase.ProcessDialogKey(keyData)

End Function



Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseDown(e)

End Sub

Public Sub New()

Trace.WriteLine(Me.VertScrollBar.Visible.ToString)

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseMove(e)

End Sub


End Class



Ken

-------------------------------

Hi,
Can you lock the colum in a datagrid so that it can not be resized by th
user?

Thanks Doug
 
K

Ken Tucker [MVP]

Hi,

Create a new windows control library project. Replace the code in
the control with confirmdeletedatagrid code. Compile the control. Add the
control to the toolbox. Add the new grid to your application.


Ken
-------------------
Hi,
Ken thanks for the code for the ConfirmDeleteDataGrid Class.

I understand the concept of inheritance but I am lost as far as implementing
an inherited control ie a DataGrid.

I have created a Class Module using Ken's code (below)

I have an existing datagrid on my form, I am retrieving a dataset from an
SQL DB (Northwind) with 2 datatables.
I have created 2 DataGridTableStyles and added them to my DataGrid and 2
DataViews.

How do I go about making my DataGrid an Inherited DataGrid that will have
the new property from the ConfirmDeleteDataGrid Class

I have hit a brick wall here and have not been able to find any help on MSDN
site.

Thanks for any pointers,

Doug

Public Class ConfirmDeleteDataGrid

Inherits DataGrid

Public Event DeletedRow(ByVal sender As Object, ByVal e As EventArgs)

Private Const WM_KEYDOWN = &H100



Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean

Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)

If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then

If MessageBox.Show("Delete This Row?", "Confirm Delete", _

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

Return MyBase.PreProcessMessage(msg)

End Function

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean

Dim pt As Point

Dim hti As DataGrid.HitTestInfo

pt = Me.PointToClient(Cursor.Position)

hti = Me.HitTest(pt)

If keyData = Keys.Delete Then

If hti.Type = Me.HitTestType.RowHeader Then

If MessageBox.Show("Delete this row?", "Confirm Delete", _

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

End If

Return MyBase.ProcessDialogKey(keyData)

End Function



Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseDown(e)

End Sub

Public Sub New()

Trace.WriteLine(Me.VertScrollBar.Visible.ToString)

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseMove(e)

End Sub


End Class



Ken

-------------------------------

Hi,
Can you lock the colum in a datagrid so that it can not be resized by th
user?

Thanks Doug
 
D

Doug Bell

Hi Ken,

Thanks

Doug

Ken Tucker said:
Hi,

Create a new windows control library project. Replace the code in
the control with confirmdeletedatagrid code. Compile the control. Add the
control to the toolbox. Add the new grid to your application.


Ken
-------------------
Hi,
Ken thanks for the code for the ConfirmDeleteDataGrid Class.

I understand the concept of inheritance but I am lost as far as implementing
an inherited control ie a DataGrid.

I have created a Class Module using Ken's code (below)

I have an existing datagrid on my form, I am retrieving a dataset from an
SQL DB (Northwind) with 2 datatables.
I have created 2 DataGridTableStyles and added them to my DataGrid and 2
DataViews.

How do I go about making my DataGrid an Inherited DataGrid that will have
the new property from the ConfirmDeleteDataGrid Class

I have hit a brick wall here and have not been able to find any help on MSDN
site.

Thanks for any pointers,

Doug

Public Class ConfirmDeleteDataGrid

Inherits DataGrid

Public Event DeletedRow(ByVal sender As Object, ByVal e As EventArgs)

Private Const WM_KEYDOWN = &H100



Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean

Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)

If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then

If MessageBox.Show("Delete This Row?", "Confirm Delete", _

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

Return MyBase.PreProcessMessage(msg)

End Function

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean

Dim pt As Point

Dim hti As DataGrid.HitTestInfo

pt = Me.PointToClient(Cursor.Position)

hti = Me.HitTest(pt)

If keyData = Keys.Delete Then

If hti.Type = Me.HitTestType.RowHeader Then

If MessageBox.Show("Delete this row?", "Confirm Delete", _

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

End If

Return MyBase.ProcessDialogKey(keyData)

End Function



Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseDown(e)

End Sub

Public Sub New()

Trace.WriteLine(Me.VertScrollBar.Visible.ToString)

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseMove(e)

End Sub


End Class



Ken

-------------------------------

Hi,
Can you lock the colum in a datagrid so that it can not be resized by th
user?

Thanks Doug
 

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