How can I get the height of a ListView item?

前端 未结 3 685
生来不讨喜
生来不讨喜 2020-12-21 02:39

I have ListView and I need to determine item height.

相关标签:
3条回答
  • 2020-12-21 03:10

    I had the same question however there is one issue - until the listview is drawn the values aren't set. And you may want to be able to set the sizes before you add any items (if for example I want to dry a listview that can display 5 entries but will start off empty).

    Therefore my workaround was to run the following code, which forces the control to be rendered but without displaying it, in the application's initialisation section and save the values as global variables for later use. And, to get around listviews with different font sizes, to only store the difference between the height and the font height:

    Dim lvwTemp As New ListView
    lvwTemp.View = View.Details
    lvwTemp.Columns.Add("test")
    lvwTemp.Items.Add("test")
    Dim zTempBitmap As New Bitmap(100, 100)
    lvwTemp.DrawToBitmap(zTempBitmap, New Rectangle(0, 0, 100, 100))
    zTempBitmap.Dispose()
    gintListviewHeaderHeightMinusFontSize = lvwTemp.Items(0).GetBounds(ItemBoundsPortion.Entire).Top - lvwTemp.Font.Height
    gintListviewItemHeightMinusFontSize = lvwTemp.Items(0).GetBounds(ItemBoundsPortion.Entire).Height - lvwTemp.Font.Height
    
    0 讨论(0)
  • 2020-12-21 03:23

    I am not 100% sure but this might help:

    int itemHeight = listView.Items[itemIndex].GetBounds(ItemBoundsPortion.Entire).Height;
    
    0 讨论(0)
  • 2020-12-21 03:25

    You can use the GetItemRect() method:

    int itemHeight = yourListView.GetItemRect(itemIndex).Height;
    
    0 讨论(0)
提交回复
热议问题