anusdesai
asked on
How to find a column number in listview which is clicked
Hi,
How to find a column number in listview which is clicked
Regards.
How to find a column number in listview which is clicked
Regards.
The code from jpaulino needs to be placed in the MouseClick-event !
ASKER
Hi,
its pointing to wrong columns....i have 13 columns but maximum i get is 6 from the function
its pointing to wrong columns....i have 13 columns but maximum i get is 6 from the function
Are all your columns on the screen ? I guess you have a scrollbar in your listbox !
ASKER
Hi,
If i place
The code from jpaulino needs to be placed in the MouseClick-event
i get e.X
X is not a member of system.eventargs.
If i place
The code from jpaulino needs to be placed in the MouseClick-event
i get e.X
X is not a member of system.eventargs.
Thanks Dhaest I forgot to tell it :-)
Anusdesai Its works correctly with the listview
Anusdesai Its works correctly with the listview
anusdesai in the mouse down event.
But if you have a scrollbar (like Dhaest already post it) it does not work.
ASKER
Stilll no luck...it counts max 6 columns....are any settings needed
hover over....
full row select ?
hover over....
full row select ?
This will only work if you click on the columnheader (title)
Private Sub listView1_ColumnClick(ByVa l sender As Object, ByVal e As ColumnClickEventArgs)
Dim colIndex As Integer = e.Column
MessageBox.Show(listView1. Columns(co lIndex).Te xt)
End Sub
Private Sub listView1_ColumnClick(ByVa
Dim colIndex As Integer = e.Column
MessageBox.Show(listView1.
End Sub
You still not anwer the question: are all column visible (no scrollbar) ?
ASKER
Sorry this does not suffice the requirement...user can click anywhere on listview where i have to fire a pop up menu depending on the column selected
>> Sorry this does not suffice the requirement...user can click anywhere on listview where i have to fire a pop up menu depending on the column selected
I already thought that, but can you please answer jpaulino and mine question:
Are all columns visible without scrollbar ?
I already thought that, but can you please answer jpaulino and mine question:
Are all columns visible without scrollbar ?
ASKER
Yes all columns are visible...there is no scrollbar
Then this should work ...
Private Sub listView1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim colstart As Integer = 0
Dim colend As Integer = 0
Dim x As Integer
For x = 0 To (ListView1.Columns.Count - 1)
colend = colend + ListView1.Columns(x).Width
If colstart <= e.X And e.X <= colend Then
Label1.Text = "Column clicked: " & x + 1
Exit For
End If
colstart = colstart + ListView1.Columns(x).Width
Next
Private Sub listView1_MouseClick(ByVal
Dim colstart As Integer = 0
Dim colend As Integer = 0
Dim x As Integer
For x = 0 To (ListView1.Columns.Count - 1)
colend = colend + ListView1.Columns(x).Width
If colstart <= e.X And e.X <= colend Then
Label1.Text = "Column clicked: " & x + 1
Exit For
End If
colstart = colstart + ListView1.Columns(x).Width
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Same time Dhaest :-)
ASKER
Sorry it still doesnt work...
i have setting hover over true..select full row false
All bound columns....
i have setting hover over true..select full row false
All bound columns....
If it doesnt work post your code here
ASKER
Private Sub ListControls_MouseDown(ByV
Dim colstart As Integer = 0
Dim colend As Integer = 0
Dim x As Integer
For x = 0 To (Me.ListControls.Columns.C
colend = colend + Me.ListControls.Columns(x)
If colstart <= e.X And e.X <= colend Then
MsgBox("Column clicked: " & x + 1)
Exit For
End If
colstart = colstart + Me.ListControls.Columns(x)
Next
End Sub
Public Sub LoadColumns()
'Create a column for each record in the reports table
'set the width of the column to the length of the report name
Dim SQL As String = ""
Dim dt As New DataTable
Dim i As Integer = 2
Dim Col As System.Windows.Forms.ListV
Dim colstr As String = ""
Col = ListControls.Columns
Dim orow As DataRow
Sql = "SELECT NAME FROM abc"
Dim colcnt As Integer = 1
dt = Populate(SQL)
For Each orow In dt.Rows
Try
colstr = orow(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
colcnt = colcnt + 1
Col.Insert(colcnt, "", colstr, 1000)
Next
sizeTheColumns(Me.ListCont
End Sub
Public Sub sizeTheColumns(ByVal lvw As ListView)
For i As Integer = 0 To lvw.Columns.Count - 1
Application.DoEvents()
lvw.Columns(i).Width = -2
Next i
'If lvw.Columns.Count > 1 Then
' lvw.Columns(0).Width = lvw.Columns(i).Width + 1
'End If
End Sub
If I undersatnd it correctly, then you hide the columns (size = -2 ?)
ASKER
Private Sub ListControls_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListControls.Click
Dim Itm As System.Windows.Forms.ListV iew.ListVi ewItemColl ection 'items in batch list
Itm = ListControls.Items
With ListControls.FocusedItem
If Not .Selected Then Exit Sub
SaveRunSettings = True
If .ImageIndex = 0 Then
.ImageIndex = 2 'UNTICK
Else
.ImageIndex = 0 'TICK
End If
ListControls.Visible = False
ListControls.Visible = True
End With
End Sub
Dim Itm As System.Windows.Forms.ListV
Itm = ListControls.Items
With ListControls.FocusedItem
If Not .Selected Then Exit Sub
SaveRunSettings = True
If .ImageIndex = 0 Then
.ImageIndex = 2 'UNTICK
Else
.ImageIndex = 0 'TICK
End If
ListControls.Visible = False
ListControls.Visible = True
End With
End Sub
>> If I undersatnd it correctly, then you hide the columns (size = -2 ?)
Change it to 0
Change it to 0
ASKER
Fine..cheers will try and right back
ASKER
Worked....cheers!!!!!!!!!! !
Anusdesai you should slit the point &
ASKER
Hi,
What if i my listview is scrollable?then how can i find the column?
What if i my listview is scrollable?then how can i find the column?
In that case, I don't think it's possible (perhaps it is, but I haven't seen it before)
Dim colstart As Integer = 0
Dim colend As Integer = 0
Dim x As Integer
For x = 0 To (ListView1.Columns.Count - 1)
colend = colend + ListView1.Columns(x).Width
If colstart <= e.X And e.X <= colend Then
Label1.Text = "Column clicked: " & x + 1
Exit For
End If
colstart = colstart + ListView1.Columns(x).Width
Next