簡體   English   中英

刷新不會更新所有者繪圖ListBox項的高度

[英]Refresh doesn't update owner-draw ListBox item height

我有DrawMode = OwnerDrawVariable ListBox 當我動態更改一個(或多個)項目的高度並執行

listBox1.Refresh();

那么新項目的高度將被忽略,它將僅正確地重新粉刷:

拉拉拉

Ok -最初是展開的項目, Not ok -是通過鼠標展開的。

度量項目代碼並不復雜,我已經檢查了斷點, e.ItemHeight = 90e.ItemHeight = 90 ,但是,項目的高度仍為20

    private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
    {
        // ... get item
        e.ItemHeight = 20;
        if(!collapsed)
            e.ItemHeight = 20 + 10 * n; // n - number of child rows
    }

問題:可以嗎(可行)

listBox1.DataSource = null;
listBox1.DataSource = list; // list of my items

還是我錯過了某種方法(嘗試了InvalidateUpdate )?

對我而言,OnMeasureItem事件僅在刪除所有項目並再次添加回它們后才起作用。 我不在C#中工作,所以代碼在delphi中,但是它應該足夠好。

var
  tmp: TStrings;
  I: Integer;
begin
  tmp := TStrings.Create();
  try
    for I := 0 to ListBox1.Items.Count - 1 do
      tmp.Add(ListBox1.Items[I]);

    ListBox1.Items.Clear;


    for I := 0 to ListBox1.Items.Count - 1 do
      ListBox1.Items.Add(tmp[I]);

  finally
    tmp.Free;
  end;
end;

它對我有用,因為我只將TListBox用作顯示信息的控件,而不是存儲它們,所以我只是制作了沒有任何其他變量的循環。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM