里面的ListView GridView的列力大小调整力大、里面、ListView、GridView

2023-09-04 00:06:33 作者:对你爱爱爱不完

我有一个的ListView WPF控件与的GridView 。我想调整的GridView 列时的列变化的​​内容。

I have a ListView WPF control with a GridView. I'd like to resize the GridView columns when the content of the columns changes.

我有几个不同的数据集,但是当我从一个到另一个改变,每个列的大小适合previous数据。我想动态更新。我该怎么办呢?

I have several distinct data sets but when I change from one to another, the size of each columns fits the previous data. I'd like to update dynamically. How can I do that?

推荐答案

最后,就这一个了一定的成效。我已经找到一种方法来做到这一点最初做了同样的自动调整大小,当列标题的夹持被双击。

Finally, some results on this one. I've found a way to do the same auto-sizing that is done initially and when the gripper on a column header is double clicked.

public void AutoSizeColumns()
{
    GridView gv = listView1.View as GridView;
    if (gv != null)
    {
        foreach (var c in gv.Columns)
        {
            // Code below was found in GridViewColumnHeader.OnGripperDoubleClicked() event handler (using Reflector)
            // i.e. it is the same code that is executed when the gripper is double clicked
            if (double.IsNaN(c.Width))
            {
                c.Width = c.ActualWidth;
            }
            c.Width = double.NaN;
        }
    }
}
 
精彩推荐
图片推荐