记一些C#窗体应用编程中的小问题。git
this.dataGridView1.Rows[i].Selected = true;
后,在实际显示的时候,确实第i
被选中,然而经过CurrentRow
取值都是第一行,并且查看选中行标确实0this.dataGridView1.Rows[i].Selected = true; this.dataGridView1.CurrentCell = this.dataGridView1.Rows[i].Cells[0]; // 关键
DataBindingComplete
事件this.dataGridView1.ClearSelection();
,也能够在其余地方调用清空选择行。KeyPress
事件,其中实现private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) }
关于带有小数点的数字校验可查看winForm控制输入框只接受数字输入数据库
Sorted
事件,在该事件中从新设置显示效果。DataTable dt = this.dataGridView.DataSource as DataTable
, 这句话能够将DataGridView的的数据转到dt中,其实dt所持有的引用就是DataGridView的数据源,也即dt若是发生了改变,DataGridView也会发生改变。DataTable dt = (this.dataGridView.DataSource as DataTable).copy()
dt.DefaultView.Sort = "BH DESC";
按照编号降序排序(控制默认最小), 注意此时的dt并无按照意愿排序,由于还差一步编程
dt = dt.DefaultView.ToTable();
须要从新ToTable();数组
DataRow[] drs = dt.Select(" BH is not null"); // 查询BH不为空的记录
返回的是DataRow 数组this
未完,待续。。。code