By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

Datagrid question

P: n/a
I have a custom Datagrid that I want to do somthing with. When I resize a column I want a tooltip like box to come up and tell me
the width of the column. Is that hard to do? Posted is the code for what I currently have.

Thanks
Scott

Public Class MyDataGrid
Inherits DataGrid

Public Event MyVScroll As ScrollEventHandler
Public Event MyHScroll As ScrollEventHandler

Protected Overrides Sub GridVScrolled(ByVal sender As Object, ByVal e As ScrollEventArgs)
MyBase.GridVScrolled(Me, e)
OnMyVScroll(e)
End Sub

Protected Overrides Sub GridHScrolled(ByVal sender As Object, ByVal e As ScrollEventArgs)
MyBase.GridHScrolled(sender, e)
OnMyHScroll(e)
End Sub

Protected Sub OnMyVScroll(ByVal e As ScrollEventArgs)
RaiseEvent MyVScroll(Me, e)
End Sub

Protected Sub OnMyHScroll(ByVal e As ScrollEventArgs)
RaiseEvent MyHScroll(Me, e)
End Sub

Public Sub SynVScroll(ByVal e As ScrollEventArgs)
MyBase.GridVScrolled(Me, e)
End Sub

Public Sub SynHScroll(ByVal e As ScrollEventArgs)
MyBase.GridHScrolled(Me, e)
End Sub
End Class
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Here is an example. I use the mouse move event to set the
tooltip text.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter

Dim conn As SqlConnection

Dim ds As New DataSet

strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Customers", conn)

da.Fill(ds, "Customers")

SetupGrid()

DataGrid1.DataSource = ds.Tables("Customers")

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Customers"

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ContactName"

..HeaderText = "Name"

..Width = 150

End With

Dim colID As New DataGridTextBoxColumn

With colID

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 80

End With

Dim colRegion As New DataGridTextBoxColumn

With colRegion

..MappingName = "Region"

..HeaderText = "Region"

..Width = 80

..NullText = ""

End With

ts.GridColumnStyles.Add(colID)

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colRegion)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colRegion = Nothing

colName = Nothing

colID = Nothing

End Sub

Private Sub DataGrid1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseMove

Dim hti As DataGrid.HitTestInfo

hti = DataGrid1.HitTest(e.X, e.Y)

If hti.Type = DataGrid.HitTestType.ColumnResize Then

Dim strOut As String

strOut = String.Format("Column Width {0}",
DataGrid1.TableStyles(0).GridColumnStyles.Item(hti .Column).Width)

ToolTip1.SetToolTip(DataGrid1, strOut)

End If

End Sub

Ken

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

"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a custom Datagrid that I want to do somthing with. When I resize a
column I want a tooltip like box to come up and tell me
the width of the column. Is that hard to do? Posted is the code for what
I currently have.

Thanks
Scott

Public Class MyDataGrid
Inherits DataGrid

Public Event MyVScroll As ScrollEventHandler
Public Event MyHScroll As ScrollEventHandler

Protected Overrides Sub GridVScrolled(ByVal sender As Object, ByVal e As
ScrollEventArgs)
MyBase.GridVScrolled(Me, e)
OnMyVScroll(e)
End Sub

Protected Overrides Sub GridHScrolled(ByVal sender As Object, ByVal e As
ScrollEventArgs)
MyBase.GridHScrolled(sender, e)
OnMyHScroll(e)
End Sub

Protected Sub OnMyVScroll(ByVal e As ScrollEventArgs)
RaiseEvent MyVScroll(Me, e)
End Sub

Protected Sub OnMyHScroll(ByVal e As ScrollEventArgs)
RaiseEvent MyHScroll(Me, e)
End Sub

Public Sub SynVScroll(ByVal e As ScrollEventArgs)
MyBase.GridVScrolled(Me, e)
End Sub

Public Sub SynHScroll(ByVal e As ScrollEventArgs)
MyBase.GridHScrolled(Me, e)
End Sub
End Class

Nov 21 '05 #2

P: n/a
Well, I found a VERY SIMPLE solution to this (As is usually the case in .Net) and I thought I would post this in case someone else
was looking for this solution.

There is a WidthChanged Event on the TextBoxDatagridColumn object that I just capture and then sync the datagrids.

IE

Private Sub TopToBottom_WidthChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameColumn.WidthChanged,
SourceColumn.WidthChanged, PayerDescColumn.WidthChanged, Reached90Column.WidthChanged
PreviousNameColumn.Width = NameColumn.Width
PreviousSourceColumn.Width = SourceColumn.Width
PreviousPayerDescColumn.Width = PayerDescColumn.Width
PreviousReached90Column.Width = Reached90Column.Width
End Sub

Private Sub BottomToTop_WidthChange(ByVal sender As Object, ByVal e As EventArgs) Handles PreviousNameColumn.WidthChanged,
PreviousSourceColumn.WidthChanged, PreviousPayerDescColumn.WidthChanged, PreviousReached90Column.WidthChanged
NameColumn.Width = PreviousNameColumn.Width
SourceColumn.Width = PreviousSourceColumn.Width
PayerDescColumn.Width = PreviousPayerDescColumn.Width
Reached90Column.Width = PreviousReached90Column.Width
End Sub

"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a custom Datagrid that I want to do somthing with. When I resize a column I want a tooltip like box to come up and tell me
the width of the column. Is that hard to do? Posted is the code for what I currently have.

Thanks
Scott

Public Class MyDataGrid
Inherits DataGrid

Public Event MyVScroll As ScrollEventHandler
Public Event MyHScroll As ScrollEventHandler

Protected Overrides Sub GridVScrolled(ByVal sender As Object, ByVal e As ScrollEventArgs)
MyBase.GridVScrolled(Me, e)
OnMyVScroll(e)
End Sub

Protected Overrides Sub GridHScrolled(ByVal sender As Object, ByVal e As ScrollEventArgs)
MyBase.GridHScrolled(sender, e)
OnMyHScroll(e)
End Sub

Protected Sub OnMyVScroll(ByVal e As ScrollEventArgs)
RaiseEvent MyVScroll(Me, e)
End Sub

Protected Sub OnMyHScroll(ByVal e As ScrollEventArgs)
RaiseEvent MyHScroll(Me, e)
End Sub

Public Sub SynVScroll(ByVal e As ScrollEventArgs)
MyBase.GridVScrolled(Me, e)
End Sub

Public Sub SynHScroll(ByVal e As ScrollEventArgs)
MyBase.GridHScrolled(Me, e)
End Sub
End Class

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.