How to get column index of clicked column of listview that hasn't listview item?

Andrea Rossi

I have done this and it works fine :

private int getcolumn()
{
    Point mousePosition = base.PointToClient(Control.MousePosition);
    ListViewHitTestInfo hit = base.HitTest(mousePosition);   
    return hit.Item.SubItems.IndexOf(hit.SubItem); 
}

But works if in the listview there is at least one item. My list is empty, so how can i get column index? Thanks in advance.

kttii

An empty list is going to return a null subitem.

However, while the example below is not very elegant, you can see how to use the Y position to determine which column the Y is associated with:

private int getcolumn()
{
    Point mousePosition = base.PointToClient(Control.MousePosition);
    switch(mousePosition.Y)
    {
        case mousePosition.Y >= 0 && mousePosition.Y <= base.Columns(0).Width:
            Return base.Columns(0).index
            break;
        case mousePosition.Y >= base.Columns(0).Width && mousePosition.Y <= base.Columns(1).Width:
            Return base.Columns(1).index
            break;
        case mousePosition.Y >= base.Columns(0).Width + base.Columns(1).Width && mousePosition.Y <= base.Columns(2).Width:
            Return base.Columns(2).index
            break;
        default:
            Return -1
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Get Clicked ListView Item

From Dev

Determine column of header clicked in a ListView?

From Dev

How to get the index of a listview item by it's text

From Dev

how to get listview selected item text when clicked on AlertDialog button

From Dev

Get the index of Item selected in ListView

From Dev

Hold and get ListView Item index

From Dev

How to sort a ListView by a column?

From Dev

get value from database column by listview item click

From Dev

ListView - get adjacent items of the clicked item

From Dev

How to get the data of a ListView item the user has clicked on with listview.GetItemAtPosition(e.Position)?

From Dev

Get column index of clicked column in gridview

From Dev

How to display clicked listview item in another activity

From Dev

ListView get second column value

From Dev

How to Get the Index of the First Item Showing in ListView in C#

From Dev

How to get selected list item in listview by using selected index

From Dev

how to display a listview when clicked on the item of a listview with the use of arraylist?

From Dev

ListView - Grabbing a column value from the selected item

From Dev

ListView - Grabbing a column value from the selected item

From Dev

how to get an item from a listview

From Dev

unable to get asp listView selected item index

From Java

How to add a ListView to a Column in Flutter?

From Dev

How to add to specific listview column

From Dev

How to read a column cell in Listview

From Dev

How to search in a particular column in a Listview?

From Dev

How to read a column cell in Listview

From Dev

How to set ListView column dynamically?

From Dev

How to get the column value of the selected row in wpf listview

From Dev

How to get the ActualWidth of a auto-fit width column in a listview?

From Dev

how to get the position of a image in a listview and toggle if another image is clicked in the listview

Related Related

  1. 1

    How to Get Clicked ListView Item

  2. 2

    Determine column of header clicked in a ListView?

  3. 3

    How to get the index of a listview item by it's text

  4. 4

    how to get listview selected item text when clicked on AlertDialog button

  5. 5

    Get the index of Item selected in ListView

  6. 6

    Hold and get ListView Item index

  7. 7

    How to sort a ListView by a column?

  8. 8

    get value from database column by listview item click

  9. 9

    ListView - get adjacent items of the clicked item

  10. 10

    How to get the data of a ListView item the user has clicked on with listview.GetItemAtPosition(e.Position)?

  11. 11

    Get column index of clicked column in gridview

  12. 12

    How to display clicked listview item in another activity

  13. 13

    ListView get second column value

  14. 14

    How to Get the Index of the First Item Showing in ListView in C#

  15. 15

    How to get selected list item in listview by using selected index

  16. 16

    how to display a listview when clicked on the item of a listview with the use of arraylist?

  17. 17

    ListView - Grabbing a column value from the selected item

  18. 18

    ListView - Grabbing a column value from the selected item

  19. 19

    how to get an item from a listview

  20. 20

    unable to get asp listView selected item index

  21. 21

    How to add a ListView to a Column in Flutter?

  22. 22

    How to add to specific listview column

  23. 23

    How to read a column cell in Listview

  24. 24

    How to search in a particular column in a Listview?

  25. 25

    How to read a column cell in Listview

  26. 26

    How to set ListView column dynamically?

  27. 27

    How to get the column value of the selected row in wpf listview

  28. 28

    How to get the ActualWidth of a auto-fit width column in a listview?

  29. 29

    how to get the position of a image in a listview and toggle if another image is clicked in the listview

HotTag

Archive