jeudi 8 mai 2014

c# - largeur de la colonne d'un DataGrid dans une Application de Windows Mobile - Stack Overflow


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!




Change this line


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

to


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

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



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!



Change this line


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

to


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

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


0 commentaires:

Enregistrer un commentaire