我在尝试调整数据网格列的宽度时遇到问题。我使用了此处发布的答案,但无法解决。
我正在使用对象列表作为数据源。在这个简单的示例中,我刚刚创建了一个智能设备应用程序,并添加了一个数据网格。然后我的代码是这个:
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;
}
}
宽度保持不变。你有线索吗?谢谢!