Windows Mobile 应用程序中 DataGrid 的列宽 [英] Column width of a DataGrid in a Windows Mobile Application

查看:25
本文介绍了Windows Mobile 应用程序中 DataGrid 的列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试调整数据网格列的宽度时遇到问题.我使用了此处发布的答案,但是我解决不了.

I'm having problems trying to adjust the width of a column of a datagrid. I used the answer posted here, but I can't solve it.

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

I'm using a List of objects as a datasource. In this simple example, I have just created a smart device application, and just added a datagrid. Then my code is this one:

    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;
    }
}

宽度保持不变.你有什么线索吗?谢谢!

The width remains the same. Do you have a clue? Thank you!

推荐答案

更改此行

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

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

哦,4000 对于手机来说有点大,但我认为这是一个错字.

Oh, and 4000 is a little big for a mobile but I assume that's a typo.

这篇关于Windows Mobile 应用程序中 DataGrid 的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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