469,963 Members | 1,293 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

how to add dynamic tooltip when dragging scrollbar of datagridview

Hello,

Some database applicatins have a tooltip feature where when you are dragging
the scrollbar of the table view a tooltip appears next to the mouse cursor
displaying the approximate record number you are scrolling past (Excel,
Access). Sql server has the rownumbers on the Row Header column of its table
view.

Ideally, I would like to add row numbers to the Row Header column of the
datagridview like sql server - Any suggestions appreciated how I could do
this. Is there a property on the datagridview I could set?

The other idea (the idea of the original post) - how can I add a dynamic
tooltip like Excel/Access to display what record number I am passing throught
as I drag the scrollbar?

Thanks,
Rich
Sep 1 '06 #1
2 7149
Well, I started focusing on how to write to the RowHeader Cells of the
datagridview and came up with this:

Private Sub OnCellPainting(ByVal sender As Object, ByVal e As
DataGridViewCellPaintingEventArgs) Handles dgrv1.CellPainting
Dim fnt As New Font("Arial", 8)
Dim rect As New Rectangle(e.CellBounds.X, e.CellBounds.Y,
e.CellBounds.Width, e.CellBounds.Height)

Static i As Integer
If i RecCount Then i = 0
i += 1
If (e.ColumnIndex < 0) AndAlso (e.RowIndex 0) Then
e.Graphics.FillRectangle(Brushes.Lime, e.CellBounds)
e.Graphics.DrawString(i.ToString, fnt, Brushes.Black, e.CellBounds.X + 3,
e.CellBounds.Y + 3)
e.Graphics.DrawRectangle(Pens.Black, rect)
e.Handled = True
End If

End Sub
Apparently, you have to override the initial paint event of the datagridview
- and I do this by donig my own painting. And, of course, I have to draw my
own cells (rectangles) in the RowHeader column. This is actually working
fine. Where I still have a problem is in the row numbering. I was using a
static int - maybe I should use a global int. The other problem is that this
paint event keeps getting invoked, so the numbers are constantly changing
every time I scroll the datagridview and so much as hover the mouse over it.

"Rich" wrote:
Hello,

Some database applicatins have a tooltip feature where when you are dragging
the scrollbar of the table view a tooltip appears next to the mouse cursor
displaying the approximate record number you are scrolling past (Excel,
Access). Sql server has the rownumbers on the Row Header column of its table
view.

Ideally, I would like to add row numbers to the Row Header column of the
datagridview like sql server - Any suggestions appreciated how I could do
this. Is there a property on the datagridview I could set?

The other idea (the idea of the original post) - how can I add a dynamic
tooltip like Excel/Access to display what record number I am passing throught
as I drag the scrollbar?

Thanks,
Rich
Sep 1 '06 #2
On Fri, 1 Sep 2006 15:03:02 -0700, Rich <Ri**@discussions.microsoft.comwrote:
>Well, I started focusing on how to write to the RowHeader Cells of the
datagridview and came up with this:

Private Sub OnCellPainting(ByVal sender As Object, ByVal e As
DataGridViewCellPaintingEventArgs) Handles dgrv1.CellPainting
Dim fnt As New Font("Arial", 8)
Dim rect As New Rectangle(e.CellBounds.X, e.CellBounds.Y,
e.CellBounds.Width, e.CellBounds.Height)

Static i As Integer
If i RecCount Then i = 0
i += 1
If (e.ColumnIndex < 0) AndAlso (e.RowIndex 0) Then
e.Graphics.FillRectangle(Brushes.Lime, e.CellBounds)
e.Graphics.DrawString(i.ToString, fnt, Brushes.Black, e.CellBounds.X + 3,
e.CellBounds.Y + 3)
e.Graphics.DrawRectangle(Pens.Black, rect)
e.Handled = True
End If

End Sub
Apparently, you have to override the initial paint event of the datagridview
- and I do this by donig my own painting. And, of course, I have to draw my
own cells (rectangles) in the RowHeader column. This is actually working
fine. Where I still have a problem is in the row numbering. I was using a
static int - maybe I should use a global int. The other problem is that this
paint event keeps getting invoked, so the numbers are constantly changing
every time I scroll the datagridview and so much as hover the mouse over it.

"Rich" wrote:
>Hello,

Some database applicatins have a tooltip feature where when you are dragging
the scrollbar of the table view a tooltip appears next to the mouse cursor
displaying the approximate record number you are scrolling past (Excel,
Access). Sql server has the rownumbers on the Row Header column of its table
view.

Ideally, I would like to add row numbers to the Row Header column of the
datagridview like sql server - Any suggestions appreciated how I could do
this. Is there a property on the datagridview I could set?

The other idea (the idea of the original post) - how can I add a dynamic
tooltip like Excel/Access to display what record number I am passing throught
as I drag the scrollbar?

Thanks,
Rich

Maybe these will help:

In the DataGridView Scroll Event," e.NewValue" returns the row number of the current, first
displayed row. Scrolling the complete grid will result in the last returned NewValue of the total
rows minus the displayed row count.

Dim i As Integer = Me.DataGridView.Rows.GetRowCount(DataGridViewEleme ntStates.Displayed)
Where"i" is the number of displayed rows.

(i + e.NewValue -1) >>>Scrolling returns row number starting with last visible row to the end row.

Gene
Sep 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Vinny Vin | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.