Windows Mobile 应用程序中 DataGrid 的列宽

2023-11-22

我在尝试调整数据网格列的宽度时遇到问题。我使用了发布的答案here,但我无法解决它。

我使用对象列表作为数据源。在这个简单的示例中,我刚刚创建了一个智能设备应用程序,并添加了一个数据网格。那么我的代码是这样的:

    public Form1()
    {            
        InitializeComponent();

        List<Prueba> lista = new List<Prueba>();
        lista.Add(new Prueba("uno", "dos"));
        lista.Add(new Prueba("tres", "cuatro"));

        dataGrid1.DataSource = lista;
        DataGridTableStyle tableStyle = new DataGridTableStyle();
        tableStyle.MappingName = lista.GetType().ToString();
        DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn();
        tbcName.Width = 4000;
        tbcName.MappingName = "UNO";
        tbcName.HeaderText = "UNO";
        tableStyle.GridColumnStyles.Add(tbcName);
        dataGrid1.TableStyles.Clear();
        dataGrid1.TableStyles.Add(tableStyle);
    }
}

public class Prueba
{
    public string UNO { get; set; }
    public string DOS { get; set; }

    public Prueba(string uno, string dos)
    {
        this.UNO = uno;
        this.DOS = dos;
    }
}

宽度保持不变。你有线索吗?谢谢你!


改变这一行

tableStyle.MappingName = lista.GetType().ToString();

to

tableStyle.MappingName = lista.GetType().Name;

哦,4000 对于手机来说有点大,但我认为这是一个拼写错误。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Windows Mobile 应用程序中 DataGrid 的列宽 的相关文章

随机推荐