【问题标题】:C#: Alignment of text into a DataGrid for data loaded from a DataTableC#:为从 DataTable 加载的数据将文本对齐到 DataGrid
【发布时间】:2016-04-21 13:54:13
【问题描述】:

场景是根据单元格的内容更改单元格文本的对齐方式。但是数据位于从 DataTable 中获取其值的 DataGrid 中。加载到 DataGrid 时如何更改对齐方式。谢谢!

My Grid should look like this

【问题讨论】:

标签: c# winforms alignment


【解决方案1】:

您可以在DataGridViewCell中设置StyleAlignment

cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
cell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

如您所知,cell 变量可以这样初始化:

DataGridViewCellcell = dataGridView1[1,2];

【讨论】:

  • 但我想从 DataGrid 访问它。经过一些搜索后,我发现我无法访问 DataTable 中的单元格。但是我如何访问一行?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-27
  • 1970-01-01
  • 2017-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多