473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Datagrid question

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
2 2288
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
0
by: Randy | last post by:
Hello, I have two questions... I have a datagrid. I'm capturing the cell via HitTestInfo. The first question is fairly simple. I'm using an example of how to capture the row/column I found on the...
3
by: BBFrost | last post by:
Ok, I know how to count the number of selected datagrid rows using the code below. What has me stumped is how to determine when the selected rows within a datagrid have been changed. The...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.