C#中DataGridView常用操作實(shí)例小結(jié)
更新時(shí)間:2015年09月01日 12:50:23 作者:我心依舊
這篇文章主要介紹了C#中DataGridView常用操作,以實(shí)例形式總結(jié)了DataGridView綁定下拉列表、設(shè)置默認(rèn)值、判斷復(fù)選框是否選中等技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了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"; } //為下拉列表設(shè)置默認(rèn)值 dgvr.Cells[4].Value = row["EntryId"].ToString(); //設(shè)置復(fù)選框是否選中 dgvr.Cells[5].Value = row["flag"].ToString() == "0" ? true : false; //在列表中找到DataGridViewLinkColumn DataGridViewLinkColumn links = dataGridView.Columns[6] as DataGridViewLinkColumn; if (links != null) { //需要設(shè)置DataGridViewLinkColumn的UseColumnTextForLinkValue屬性為true才會(huì)有作用 links.Text = "點(diǎn)擊查看"; } //在列表中找到DataGridViewButtonColumn DataGridViewButtonColumn button = dataGridView.Columns[7] as DataGridViewButtonColumn; if (button != null) { //需要設(shè)置DataGridViewButtonColumn的UseColumnTextForLinkValue屬性為true才會(huì)有作用 button.Text = "點(diǎn)擊查看"; } dataGridView.Rows.Add(dgvr); } }
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- GridView自動(dòng)增加序號(hào)(三種實(shí)現(xiàn)方式)
- C#處理datagridview虛擬模式的方法
- C#中datagridview的EditingControlShowing事件用法實(shí)例
- C#中GridView動(dòng)態(tài)添加列的實(shí)現(xiàn)方法
- C#實(shí)現(xiàn)DataGridView控件行列互換的方法
- C#實(shí)現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法
- C#實(shí)現(xiàn)3步手動(dòng)建DataGridView的方法
- asp.net中GridView數(shù)據(jù)鼠標(biāo)移入顯示提示信息
- C#中DataGridView動(dòng)態(tài)添加行及添加列的方法
- GridView使用學(xué)習(xí)總結(jié)
- 如何用jQuery實(shí)現(xiàn)ASP.NET GridView折疊伸展效果
- ASP.NET GridView中加入RadioButton不能單選的解決方案
- DataGridView展開與收縮功能實(shí)現(xiàn)
- GridView控件如何顯示序號(hào)
相關(guān)文章
淺析C#中StringBuilder類的高效及與String的對比
StringBuilder類所創(chuàng)造出來的字符串對象在拼接操作等方面比普通的string類往往要高效很多,這是它們在內(nèi)存劃分方式上的不同所決定的,下面就來淺析C#中StringBuilder類的高效及與String的對比2016-05-05利用WPF實(shí)現(xiàn)Windows屏保的制作
屏保程序的本質(zhì)上就是一個(gè)Win32?窗口應(yīng)用程序。本文將利用WPF實(shí)現(xiàn)Windows屏保的制作,文中的示例代碼簡潔易懂,對我們學(xué)習(xí)WPF有一定幫助,感興趣的可以了解一下2022-07-07C# WinForm開發(fā)中使用XML配置文件實(shí)例
這篇文章主要介紹了C# WinForm開發(fā)中使用XML配置文件實(shí)例,本文詳細(xì)講解了如何使用一個(gè)XML文件作為WinForm的配置文件,需要的朋友可以參考下2014-08-08