雷火电竞-中国电竞赛事及体育赛事平台

歡迎來(lái)到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

C#中DataGridView常用操作實(shí)例小結(jié)

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊:

本文實(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)
  {
   //綁定下來(lái)列表
   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);
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

上一篇:C#編程獲取資源文件中圖片的方法

欄    目:C#教程

下一篇:Winform消除button按下出現(xiàn)的虛線簡(jiǎn)單實(shí)現(xiàn)方法

本文標(biāo)題:C#中DataGridView常用操作實(shí)例小結(jié)

本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/7013.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有