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

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

问题描述

我在努力适应一个DataGrid的列的宽度问题。我用了答案贴 href=\"http://stackoverflow.com/questions/859464/what-is-the-datagrid-mappingname-for-a-non-datatable-datasource\">,但我不解决这个问题。

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();



to

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天全站免登陆