里面的ListView GridView的列力大小调整 [英] Force resize of GridView columns inside ListView

查看:210
本文介绍了里面的ListView GridView的列力大小调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的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;
        }
    }
}

这篇关于里面的ListView GridView的列力大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆