怎样调整表中列的宽度使其填满整个datagrid

yhtzyx 2006-06-20 05:09:55
不知该如何是好,在线等
...全文
282 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhtzyx 2006-06-20
  • 打赏
  • 举报
回复
这样写到是可以,但不能随着窗口的大小变动,能实现动态的吗
nikita007 2006-06-20
  • 打赏
  • 举报
回复
就是在你的formload里添加tablestyle就可以
private void AddCustomDataTableStyle()
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "SUP";
// 设置属性
ts1.AlternatingBackColor = Color.LightGray;


// 添加Textbox列样式,以便我们捕捉鼠标事件
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "SUP_CONTRACT_NO";
TextCol.HeaderText = "CONTRACT NO";
TextCol.Width = 50;
TextCol.ReadOnly = true;
//添加事件处理器
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);


TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "SUP_NO";
TextCol.HeaderText = "SUPPLIER NO";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "SECTIONID";
TextCol.HeaderText = "SECTIONID";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "START_DATE";
TextCol.HeaderText = "START DATE";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "END_DATE";
TextCol.HeaderText = "END DATE";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "SERVICE_NO";
TextCol.HeaderText = "SERVICE NO";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "C_FLAG";
TextCol.HeaderText = "Collection Flag";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "LP_ID";
TextCol.HeaderText = "LOGISTIC PROVIDER ID";
TextCol.Width = 100;
TextCol.ReadOnly = true;
TextCol.TextBox.Click += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

ts1.SelectionBackColor = System.Drawing.Color.Blue;

dataGrid1.TableStyles.Add(ts1);

}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧