winform 位置不空 隐藏控件_Winform dataGridView 表头展示隐藏 和 位置调用 用法

本文介绍了如何在Winform应用程序中处理dataGridView控件,包括设置DateTimePicker的显示格式、添加测试数据、响应ValueChanged事件以及实现表头的隐藏和位置调整。在ShowSetBtn_Click事件中,通过创建WeighRecordSet窗体,实现了表头的显示设置,动态调整列的DisplayIndex和Visible属性。
摘要由CSDN通过智能技术生成

66907cd66e61c19ed9725fc5316e0276.png

public partial class WeighRecord : Form { WeighRecordSet headsSet = null; public WeighRecord() { InitializeComponent(); this.RecordTimepx.Format = DateTimePickerFormat.Custom; this.RecordTimepx.CustomFormat = " "; this.GrossTimepx.Format = DateTimePickerFormat.Custom; this.GrossTimepx.CustomFormat = " "; this.TareTimepx.Format = DateTimePickerFormat.Custom; this.TareTimepx.CustomFormat = " "; //测试数据 //var list = new List(); //list.Add(new WeighRecordDto() { Number = 1 }); //list.Add(new WeighRecordDto() { Number = 2 }); //list.Add(new WeighRecordDto() { Number = 3 }); //list.Add(new WeighRecordDto() { Number = 4 }); //list.Add(new WeighRecordDto() { Number = 5 }); //this.dataGV.DataSource = list; } private void RecordTimepx_ValueChanged(object sender, EventArgs e) { this.RecordTimepx.Format = DateTimePickerFormat.Long; this.RecordTimepx.CustomFormat = null; } private void GrossTimepx_ValueChanged(object sender, EventArgs e) { this.GrossTimepx.Format = DateTimePickerFormat.Long; this.GrossTimepx.CustomFormat = null; } private void TareTimepx_ValueChanged(object sender, EventArgs e) { this.TareTimepx.Format = DateTimePickerFormat.Long; this.TareTimepx.CustomFormat = null; } //查询 private void SearchBtn_Click(object sender, EventArgs e) { } //显示设置 List childList = null; private void ShowSetBtn_Click(object sender, EventArgs e) { //填充值 if (childList == null) { childList = new List(); for (var i = 0; i < this.WeighTable.Columns.Count; i++) { if (this.WeighTable.Columns[i].Visible) { childList.Add(new TableHeader() { Name = this.WeighTable.Columns[i].HeaderText, Choice = this.WeighTable.Columns[i].Visible, }); } } } //传入值 headsSet = new WeighRecordSet(childList); //回传值 headsSet.itemTextChanged += new EventHandler((sender1, e1) => { childList = headsSet.list; //回传值 for (var j = 0; j < headsSet.list.Count; j++) { var item = headsSet.list[j]; for (var i = 0; i < this.WeighTable.Columns.Count; i++) { if (this.WeighTable.Columns[i].HeaderText == item.Name) { this.WeighTable.Columns[i].DisplayIndex = j; this.WeighTable.Columns[i].Visible = item.Choice; break; } } } }); //弹出窗体 headsSet.ShowDialog(); } }

public partial class WeighRecordSet : Form { public List list { get; set; } public event EventHandler itemTextChanged; public WeighRecordSet() { InitializeComponent(); list = new List(); list.Add(new TableHeader() { Name = "序号" }); list.Add(new TableHeader() { Name = "车牌号" }); list.Add(new TableHeader() { Name = "司机" }); list.Add(new TableHeader() { Name = "货品" }); list.Add(new TableHeader() { Name = "毛重" }); list.Add(new TableHeader() { Name = "皮重" }); list.Add(new TableHeader() { Name = "净重" }); list.Add(new TableHeader() { Name = "扣重" }); list.Add(new Tabl.........

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值