記一些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