Home > Software engineering >  Excuse me how can I get the ListView mouse in rows and columns?
Excuse me how can I get the ListView mouse in rows and columns?

Time:11-08


Excuse me how can I get the ListView mouse in rows and columns?
Like MSFlexGrid MSFlexGrid1. MouseRow and MSFlexGrid1. MouseCol the same function
Please directly, thank you first!!!!!!

CodePudding user response:

If there is no such attribute ListView that you give a good idea to solve the

CodePudding user response:

reference 1st floor flightless_bat response:
if there is no such attribute ListView that everybody to give a good idea to solve the


When the mouse move are the coordinates of the mouse relative to controls, listview fou each high and each column column column width can be obtained, then according to the mouse X can learn line, according to the Y coordinate can learn in the columns,

CodePudding user response:

reference crispy big ice cream on the second floor response:
Quote: refer to 1st floor flightless_bat response:

If there is no such attribute ListView that everybody to give a good idea to solve the


When the mouse move are the coordinates of the mouse relative to controls, listview fou each high and each column column column width can be obtained, then according to the mouse X can learn line, according to the Y coordinate can learn in the columns,

But when the scroll bar rolling, I will think of some way to the other

CodePudding user response:

reference 3 floor crispy large ice cream response:
Quote: refer to the second floor crispy big ice cream reply:

Quote: refer to 1st floor flightless_bat response:

If there is no such attribute ListView that everybody to give a good idea to solve the


When the mouse move are the coordinates of the mouse relative to controls, listview fou each high and each column column column width can be obtained, then according to the mouse X can learn line, according to the Y coordinate can learn in the columns,

But when the scroll bar rolling to another to find a way to

I am also according to this way of thinking, code has been written, is the number of lines

CodePudding user response:

Get the mouse in the "line", much easier than to obtain in the "column",

A ListView control interface functions: GetFirstVisible ()
The return value is the "top line" ListItem,
With the ListItem, know which is the "line 1";
And then press "line height", y coordinates, can calculate the line where the mouse is above,

CodePudding user response:

Change the form controls,
Listview not form controls, with MSFlexGrid is not the same,

CodePudding user response:

reference 4 floor flightless_bat response:
Quote: reference crispy big ice cream reply: 3/f

Quote: refer to the second floor crispy big ice cream reply:

Quote: refer to 1st floor flightless_bat response:

If there is no such attribute ListView that everybody to give a good idea to solve the


When the mouse move are the coordinates of the mouse relative to controls, listview fou each high and each column column column width can be obtained, then according to the mouse X can learn line, according to the Y coordinate can learn in the columns,

But when the scroll bar rolling to another to find a way to

I am also according to this way of thinking, code has been written, is the number of lines is not


About test, can solve,
A form, a lsitview (version 6.0) and paste the code below, arbitrarily change the column width, drag the scroll bar at random, and then according to the mouse point to the coordinates calculation of the cell, the results displayed in the window Caption on

 
Option Explicit

Private Sub Form_Load ()
Dim As Integer I
ListView1. View=lvwReport
ListView1. GridLines=True
For I=1 To 20
ListView1. ColumnHeaders. The Add, "col" & amp; I
ListView1. ListItems. Add, and "row" & amp; I
Next
End Sub


Private Sub ListView1_MouseMove (Button As an Integer, Shift the As an Integer, As Single x, y As Single)
Dim getRow As Long, getCol As Long
Dim itmTmp As ListItem

The Set itmTmp=ListView1. GetFirstVisible
Get the line, first of all get the first display item, the top value is the height of the column head, get rid of the fixed height,
'mouse Y divisible item height is get the mouse pointer to display area which records, coupled with the first line item index,
'is referred to in the current mouse line index
GetRow=(y - itmTmp. Top) \ itmTmp Height + itmTmp. Index

'the mouse coordinates X minus the first lines of the left, the abscissa is the most on the left side of the mouse relative to the bank,
'then computed column head width, look at the current point to which a column of

GetCol=0
Do
GetCol=getCol + 1
X=x - ListView1. ColumnHeaders (getCol). Width
Loop Until x & lt; 0


Me. The Caption=getRow & amp; ", "& amp; GetCol
End Sub

CodePudding user response:

Write a line leakage, changing the

 
Option Explicit

Private Sub Form_Load ()
Dim As Integer I
ListView1. View=lvwReport
ListView1. GridLines=True
For I=1 To 20
ListView1. ColumnHeaders. The Add, "col" & amp; I
ListView1. ListItems. Add, and "row" & amp; I
Next
End Sub


Private Sub ListView1_MouseMove (Button As an Integer, Shift the As an Integer, As Single x, y As Single)
Dim getRow As Long, getCol As Long
Dim itmTmp As ListItem

The Set itmTmp=ListView1. GetFirstVisible
Get the line, first of all get the first display item, the top value is the height of the column head, get rid of the fixed height,
'mouse Y divisible item height is get the mouse pointer to display area which records, coupled with the first line item index,
'is referred to in the current mouse line index
GetRow=(y - itmTmp. Top) \ itmTmp Height + itmTmp. Index

'the mouse coordinates X minus the first lines of the left, the abscissa is the most on the left side of the mouse relative to the bank,
'then computed column head width, look at the current point to which a column of

GetCol=0
X=x - itmTmp. Left
Do
GetCol=getCol + 1
X=x - ListView1. ColumnHeaders (getCol). Width
Loop Until x & lt; 0


Me. The Caption=getRow & amp; ", "& amp; GetCol
End Sub

CodePudding user response:

No empty listview and the row and col without hold full display area for processing, too lazy to write, and their control is a little judgment,

CodePudding user response:

reference crispy, 9/f, big ice cream reply:
not for listview and empty row and col hold full display area not handled well, too lazy to write, our judgment with control is,

Is not supported by the things you want him support,
Laborious still not feel well,
Each control has he is good at the place,nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related