how to add dynamic tooltip when dragging scrollbar of datagridview

G

Guest

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
 
G

Guest

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.
 
G

gene kelley

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.


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(DataGridViewElementStates.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
 

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