C#中DataGridView常用操作實例小結
更新時間:2015年09月01日 12:50:23 作者:我心依舊
這篇文章主要介紹了C#中DataGridView常用操作,以實例形式總結了DataGridView綁定下拉列表、設置默認值、判斷復選框是否選中等技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#中DataGridView常用操作。分享給大家供大家參考。具體如下:
public void Binder1() { DataTable tableType = DataBase.SQLDBHelper.GetDataTable("select top 200 unit_code,unit_name from unit "); DataTable table = DataBase.SQLDBHelper.GetDataTable("select top 2 * from TempProduct"); DataGridViewRow dgvr; foreach (DataRow row in table.Rows) { dgvr = new DataGridViewRow(); dgvr.CreateCells(dataGridView); dgvr.Cells[0].Value = row["Id"].ToString(); dgvr.Cells[1].Value = row["Name"].ToString(); dgvr.Cells[2].Value = row["Age"].ToString(); dgvr.Cells[3].Value = row["Address"].ToString(); //綁定下拉列表 DataGridViewComboBoxColumn dgvcbc = dataGridView.Columns[4] as DataGridViewComboBoxColumn; if (dgvcbc != null) { //綁定下來列表 dgvcbc.DataSource = tableType; dgvcbc.DisplayMember = "unit_name"; dgvcbc.ValueMember = "unit_code"; } //為下拉列表設置默認值 dgvr.Cells[4].Value = row["EntryId"].ToString(); //設置復選框是否選中 dgvr.Cells[5].Value = row["flag"].ToString() == "0" ? true : false; //在列表中找到DataGridViewLinkColumn DataGridViewLinkColumn links = dataGridView.Columns[6] as DataGridViewLinkColumn; if (links != null) { //需要設置DataGridViewLinkColumn的UseColumnTextForLinkValue屬性為true才會有作用 links.Text = "點擊查看"; } //在列表中找到DataGridViewButtonColumn DataGridViewButtonColumn button = dataGridView.Columns[7] as DataGridViewButtonColumn; if (button != null) { //需要設置DataGridViewButtonColumn的UseColumnTextForLinkValue屬性為true才會有作用 button.Text = "點擊查看"; } dataGridView.Rows.Add(dgvr); } }
希望本文所述對大家的C#程序設計有所幫助。
您可能感興趣的文章:
- GridView自動增加序號(三種實現(xiàn)方式)
- C#處理datagridview虛擬模式的方法
- C#中datagridview的EditingControlShowing事件用法實例
- C#中GridView動態(tài)添加列的實現(xiàn)方法
- C#實現(xiàn)DataGridView控件行列互換的方法
- C#實現(xiàn)綁定DataGridView與TextBox之間關聯(lián)的方法
- C#實現(xiàn)3步手動建DataGridView的方法
- asp.net中GridView數(shù)據(jù)鼠標移入顯示提示信息
- C#中DataGridView動態(tài)添加行及添加列的方法
- GridView使用學習總結
- 如何用jQuery實現(xiàn)ASP.NET GridView折疊伸展效果
- ASP.NET GridView中加入RadioButton不能單選的解決方案
- DataGridView展開與收縮功能實現(xiàn)
- GridView控件如何顯示序號
相關文章
淺析C#中StringBuilder類的高效及與String的對比
StringBuilder類所創(chuàng)造出來的字符串對象在拼接操作等方面比普通的string類往往要高效很多,這是它們在內存劃分方式上的不同所決定的,下面就來淺析C#中StringBuilder類的高效及與String的對比2016-05-05