国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#中datagridview處理非綁定列的方法

2020-01-24 01:41:32
字體:
來源:轉載
供稿:網友

本文實例講述了c#中datagridview處理非綁定列的方法。分享給大家供大家參考。具體實現方法如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using datagridview1.DataSet1TableAdapters;namespace datagridview1{ public partial class Form1 : Form {  public Form1()  {   InitializeComponent();  }  private void Form1_Load(object sender, EventArgs e)  {   CustomersTableAdapter adapter = new CustomersTableAdapter();   bindingSource1.DataSource = adapter.GetData();   dataGridView1.AutoGenerateColumns = false;   int newColIndex = dataGridView1.Columns.Add("CompanyName", "CompanyName");   dataGridView1.Columns[newColIndex].DataPropertyName = "CompanyName";   newColIndex = dataGridView1.Columns.Add("ContactName", "ContactName");   dataGridView1.Columns[newColIndex].DataPropertyName = "ContactName";   newColIndex = dataGridView1.Columns.Add("Phone", "Phone");   dataGridView1.Columns[newColIndex].DataPropertyName = "Phone";   newColIndex = dataGridView1.Columns.Add("Contact", "Contact");   dataGridView1.CellFormatting += OnCellFormatting;   dataGridView1.DataSource = bindingSource1;  }  private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)  {   if (e.ColumnIndex == dataGridView1.Columns["Contact"].Index)   {    e.FormattingApplied = true;    DataGridViewRow row = dataGridView1.Rows[e.RowIndex];    e.Value = string.Format("{0}:{1}", row.Cells["ContactName"].Value, row.Cells["Phone"].Value);   }  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巫山县| 枝江市| 海淀区| 新丰县| 高州市| 崇礼县| 湾仔区| 邵阳县| 固原市| 太康县| 黄大仙区| 陈巴尔虎旗| 建德市| 光泽县| 嘉定区| 馆陶县| 洛扎县| 民勤县| 舟曲县| 当阳市| 阿坝县| 松滋市| 沅江市| 昭觉县| 会宁县| 荆州市| 海南省| 琼海市| 安阳县| 南丹县| 吉木乃县| 巨鹿县| 托克逊县| 彭阳县| 上杭县| 揭东县| 揭东县| 康马县| 新源县| 常德市| 胶南市|