tinchos
asked on
ListView Tooltip
Hi
I'm looking forward to placing a tooltip in a listview.
In order to do that, I'm hanging to the listview's MouseMove event
and my handler looks like
private void OnListViewMouseMove(object sender, MouseEventArgs e)
{
ListViewItem lvitem = new ListViewItem();
lvitem = listView.GetItemAt(e.X,e.Y );
if( lvitem != null )
toolTip.SetToolTip( listView, "My tooltip" );
}
This shows a tooltip whose text is "My Tooltip".
Now what I want to do is to show a different text for each column.....
This would be if the mouse is over column 1, then the tooltip should be for instance "Over Column 1", if the mouse is over column 2, then the tooltip should be for instance "Over Column 2"
Any idea how to know which column I'm over (As you can see from the code, I can get the listViewItem I'm over, but don't know how to get the column I'm over)
Thanks
Tincho
I'm looking forward to placing a tooltip in a listview.
In order to do that, I'm hanging to the listview's MouseMove event
and my handler looks like
private void OnListViewMouseMove(object
{
ListViewItem lvitem = new ListViewItem();
lvitem = listView.GetItemAt(e.X,e.Y
if( lvitem != null )
toolTip.SetToolTip( listView, "My tooltip" );
}
This shows a tooltip whose text is "My Tooltip".
Now what I want to do is to show a different text for each column.....
This would be if the mouse is over column 1, then the tooltip should be for instance "Over Column 1", if the mouse is over column 2, then the tooltip should be for instance "Over Column 2"
Any idea how to know which column I'm over (As you can see from the code, I can get the listViewItem I'm over, but don't know how to get the column I'm over)
Thanks
Tincho
You may use the data of the Item that raised the event. If you wanted to use the index in the tooltip:
tooTip.SetToolTip(listView ,listView. Index.ToSt ring());
tooTip.SetToolTip(listView
ASKER
bruintje
Give me some time to check it out....
esteban_felipe
What I want to know is over which column I'm over
Give me some time to check it out....
esteban_felipe
What I want to know is over which column I'm over
This might help. Stripped it from other implementation --> shows dropdown box when user clicks on a cell. Same case though... Try it out + your code
Private col As Integer
Private row As Integer
Private Const colH As Byte = 85
Private Const colHH As Byte = 170
Private Sub lvwSQLConditions_MouseHove r(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles lvwSQLConditions.MouseHove r
row = e.Y - lvwSQLConditions.Items(0). GetBounds( ItemBounds Portion.La bel).Top
row \= lvwSQLConditions.Items(0). GetBounds( ItemBounds Portion.La bel).Heigh t
col = e.X - lvwSQLConditions.Items(0). GetBounds( ItemBounds Portion.La bel).Left
col \= colH
'hideShowCombo(False)
Select Case col
Case 0, 1
col = 0
'show tooltip
Case 2
col = 1
'show tooltip
Case 3, 4
col = 2
Case 5
col = 3
End Select
lvwSQLConditions.Items(row ).Selected = False
If col = 6 Then Exit Sub
Try
If row <> 0 Then
'check if we are allowed here
'If lvwSQLConditions.Items(row - 1).SubItems(3).Text = "" Then
'hideShowCombo(False)
'Exit Sub
'End If
End If
Catch ex As ArgumentOutOfRangeExceptio n
'hideShowCombo(False)
End Try
End Sub
hec",)
Private col As Integer
Private row As Integer
Private Const colH As Byte = 85
Private Const colHH As Byte = 170
Private Sub lvwSQLConditions_MouseHove
row = e.Y - lvwSQLConditions.Items(0).
row \= lvwSQLConditions.Items(0).
col = e.X - lvwSQLConditions.Items(0).
col \= colH
'hideShowCombo(False)
Select Case col
Case 0, 1
col = 0
'show tooltip
Case 2
col = 1
'show tooltip
Case 3, 4
col = 2
Case 5
col = 3
End Select
lvwSQLConditions.Items(row
If col = 6 Then Exit Sub
Try
If row <> 0 Then
'check if we are allowed here
'If lvwSQLConditions.Items(row
'hideShowCombo(False)
'Exit Sub
'End If
End If
Catch ex As ArgumentOutOfRangeExceptio
'hideShowCombo(False)
End Try
End Sub
hec",)
ASKER
Sorry harris
could you please give me a hand in understanding it?
Tincho
could you please give me a hand in understanding it?
Tincho
'This is the complete implementation.
'TODO: Put a timer on top so there is a delay on the tooltip display. Reason for putting the row/column variables outside the procedure.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListView1 As System.Windows.Forms.ListV iew
Friend WithEvents ColumnHeader1 As System.Windows.Forms.Colum nHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.Colum nHeader
Friend WithEvents ColumnHeader3 As System.Windows.Forms.Colum nHeader
Friend WithEvents ColumnHeader4 As System.Windows.Forms.Colum nHeader
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolT ip
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Cont ainer()
Dim ListViewItem1 As System.Windows.Forms.ListV iewItem = New System.Windows.Forms.ListV iewItem(Ne w System.Windows.Forms.ListV iewItem.Li stViewSubI tem() {New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col1Row1", System.Drawing.SystemColor s.WindowTe xt, System.Drawing.SystemColor s.Window, New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col2Row1"), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col3Row1"), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col4Row1")}, -1)
Dim ListViewItem2 As System.Windows.Forms.ListV iewItem = New System.Windows.Forms.ListV iewItem(Ne w System.Windows.Forms.ListV iewItem.Li stViewSubI tem() {New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col1Row2", System.Drawing.SystemColor s.WindowTe xt, System.Drawing.SystemColor s.Window, New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col2Row2"), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col3Row2"), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col4Row2")}, -1)
Dim ListViewItem3 As System.Windows.Forms.ListV iewItem = New System.Windows.Forms.ListV iewItem(Ne w System.Windows.Forms.ListV iewItem.Li stViewSubI tem() {New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col1Row3", System.Drawing.SystemColor s.WindowTe xt, System.Drawing.SystemColor s.Window, New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col2Row3"), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col3Row3"), New System.Windows.Forms.ListV iewItem.Li stViewSubI tem(Nothin g, "Col4Row3")}, -1)
Me.ListView1 = New System.Windows.Forms.ListV iew()
Me.ColumnHeader1 = New System.Windows.Forms.Colum nHeader()
Me.ColumnHeader2 = New System.Windows.Forms.Colum nHeader()
Me.ColumnHeader3 = New System.Windows.Forms.Colum nHeader()
Me.ColumnHeader4 = New System.Windows.Forms.Colum nHeader()
Me.ToolTip1 = New System.Windows.Forms.ToolT ip(Me.comp onents)
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Columns.AddRa nge(New System.Windows.Forms.Colum nHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4})
Me.ListView1.GridLines = True
Me.ListView1.Items.AddRang e(New System.Windows.Forms.ListV iewItem() {ListViewItem1, ListViewItem2, ListViewItem3})
Me.ListView1.Location = New System.Drawing.Point(40, 24)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(312, 120)
Me.ListView1.TabIndex = 1
Me.ListView1.View = System.Windows.Forms.View. Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Col1"
Me.ColumnHeader1.Width = 68
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Col2"
Me.ColumnHeader2.Width = 74
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Col3"
Me.ColumnHeader3.Width = 74
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Col4"
Me.ColumnHeader4.Width = 78
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(400, 261)
Me.Controls.AddRange(New System.Windows.Forms.Contr ol() {Me.ListView1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private col As Integer
Private row As Integer
'this is the default height of the cell
Private Const colH As Byte = 85
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles ListView1.MouseMove
row = e.Y - ListView1.Items(0).GetBoun ds(ItemBou ndsPortion .Label).To p
row \= ListView1.Items(0).GetBoun ds(ItemBou ndsPortion .Label).He ight
col = e.X - ListView1.Items(0).GetBoun ds(ItemBou ndsPortion .Label).Le ft
col \= colH
'hideShowCombo(False)
ToolTip1.SetToolTip(ListVi ew1, "You are in COLUMN: " & col + 1 & ", ROW: " & row + 1)
End Sub
Private Sub ListView1_SelectedIndexCha nged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexCha nged
End Sub
End Class
hec",)
'TODO: Put a timer on top so there is a delay on the tooltip display. Reason for putting the row/column variables outside the procedure.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListView1 As System.Windows.Forms.ListV
Friend WithEvents ColumnHeader1 As System.Windows.Forms.Colum
Friend WithEvents ColumnHeader2 As System.Windows.Forms.Colum
Friend WithEvents ColumnHeader3 As System.Windows.Forms.Colum
Friend WithEvents ColumnHeader4 As System.Windows.Forms.Colum
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolT
<System.Diagnostics.Debugg
Me.components = New System.ComponentModel.Cont
Dim ListViewItem1 As System.Windows.Forms.ListV
Dim ListViewItem2 As System.Windows.Forms.ListV
Dim ListViewItem3 As System.Windows.Forms.ListV
Me.ListView1 = New System.Windows.Forms.ListV
Me.ColumnHeader1 = New System.Windows.Forms.Colum
Me.ColumnHeader2 = New System.Windows.Forms.Colum
Me.ColumnHeader3 = New System.Windows.Forms.Colum
Me.ColumnHeader4 = New System.Windows.Forms.Colum
Me.ToolTip1 = New System.Windows.Forms.ToolT
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Columns.AddRa
Me.ListView1.GridLines = True
Me.ListView1.Items.AddRang
Me.ListView1.Location = New System.Drawing.Point(40, 24)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(312, 120)
Me.ListView1.TabIndex = 1
Me.ListView1.View = System.Windows.Forms.View.
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Col1"
Me.ColumnHeader1.Width = 68
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Col2"
Me.ColumnHeader2.Width = 74
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Col3"
Me.ColumnHeader3.Width = 74
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Col4"
Me.ColumnHeader4.Width = 78
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(400, 261)
Me.Controls.AddRange(New System.Windows.Forms.Contr
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private col As Integer
Private row As Integer
'this is the default height of the cell
Private Const colH As Byte = 85
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
row = e.Y - ListView1.Items(0).GetBoun
row \= ListView1.Items(0).GetBoun
col = e.X - ListView1.Items(0).GetBoun
col \= colH
'hideShowCombo(False)
ToolTip1.SetToolTip(ListVi
End Sub
Private Sub ListView1_SelectedIndexCha
End Sub
End Class
hec",)
ASKER
Sorry harris
could you please give me a hand in understanding it?
especially the ListView1_MouseMove method
Tincho
could you please give me a hand in understanding it?
especially the ListView1_MouseMove method
Tincho
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok hec
Just a question
When determining the column in which the cursor is positioned, you'll do
//determine *true* column regardless of column widths
//add up all column widths until its greater than the X location of cursor
for (col = 0; col <= colCnt - 1; col++)
{
tWidth = tWidth + listView1.Columns[col].Wid th;
if (tWidth > e.X)
{
outCol = false;
break;
}
}
But..... if I have defined the width of the column as -1 (autoadjust to the largest value in that column) or -2 (autoadjust to the header width), will it work too?
Tincho
Just a question
When determining the column in which the cursor is positioned, you'll do
//determine *true* column regardless of column widths
//add up all column widths until its greater than the X location of cursor
for (col = 0; col <= colCnt - 1; col++)
{
tWidth = tWidth + listView1.Columns[col].Wid
if (tWidth > e.X)
{
outCol = false;
break;
}
}
But..... if I have defined the width of the column as -1 (autoadjust to the largest value in that column) or -2 (autoadjust to the header width), will it work too?
Tincho
Hi Tincho,
It does. Since the calculation of the width is taking into account the current width of the listView.
You can verify this by putting a command button into the form and adding the ff code:
private void button1_Click(object sender, System.EventArgs e)
{
for (int ctr = 0; ctr < listView1.Columns.Count ; ctr++)
{
listView1.Columns[ctr].Wid th += 10;
}
}
hec",)
It does. Since the calculation of the width is taking into account the current width of the listView.
You can verify this by putting a command button into the form and adding the ff code:
private void button1_Click(object sender, System.EventArgs e)
{
for (int ctr = 0; ctr < listView1.Columns.Count ; ctr++)
{
listView1.Columns[ctr].Wid
}
}
hec",)
ASKER
Ok, let me check it and I'll let you know
Tincho
Tincho
ASKER
Harris, I have not forgotten about this one
I'm with a lot of trouble and I just couldn't try it.......
give me a few days and I'll be closing it
Thanks
Tincho
I'm with a lot of trouble and I just couldn't try it.......
give me a few days and I'll be closing it
Thanks
Tincho
ASKER
Sorry for the delay Harris, but I've been really busy and with a lot of trouble at work
Luckily, I've managed to test it today.
Thanks
Tincho
Luckily, I've managed to test it today.
Thanks
Tincho
Thats alright tinchos.
Thanks too.
hec",)
Thanks too.
hec",)
http://www.codeproject.com/cs/miscctrl/CSharpHitTest.asp
but i'm just listening in on this q needing the same ;)