c#中datagridview處理非綁定列的方法
更新時(shí)間:2015年06月20日 11:58:48 作者:zhuzhao
這篇文章主要介紹了c#中datagridview處理非綁定列的方法,實(shí)例分析了C#中datagridview的使用技巧,需要的朋友可以參考下
本文實(shí)例講述了c#中datagridview處理非綁定列的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
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);
}
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
c#之圓形無(wú)標(biāo)題欄橢圓窗體的實(shí)現(xiàn)詳解
本篇文章是對(duì)c#中圓形無(wú)標(biāo)題欄橢圓窗體的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
C# 全角和半角轉(zhuǎn)換以及判斷的簡(jiǎn)單代碼
這篇文章介紹了在C#中判斷和轉(zhuǎn)換全角半角的方法,有需要的朋友可以參考一下2013-07-07
C#與Java的MD5簡(jiǎn)單驗(yàn)證(實(shí)例代碼)
下面小編就為大家?guī)?lái)一篇C#與Java的MD5簡(jiǎn)單驗(yàn)證(實(shí)例代碼)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09
C#實(shí)現(xiàn)3步手動(dòng)建DataGridView的方法
這篇文章主要介紹了C#實(shí)現(xiàn)3步手動(dòng)建DataGridView的方法,實(shí)例分析了C#實(shí)現(xiàn)手動(dòng)創(chuàng)建DataGridView的原理與技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
C#使用Socket實(shí)現(xiàn)局域網(wǎng)聊天
這篇文章主要為大家詳細(xì)介紹了C#使用Socket實(shí)現(xiàn)局域網(wǎng)聊天的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05

