C#中datagridview的EditingControlShowing事件用法实例
本文实例讲述了C#中datagridview的EditingControlShowing事件用法。分享给大家供大家参考。具体实现方法如下:
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Text; usingSystem.Windows.Forms; usingdatagridview1.DataSet1TableAdapters; namespacedatagridview1 { publicpartialclassForm3:Form { publicForm3() { InitializeComponent(); } privatevoidForm3_Load(objectsender,EventArgse) { CustomersTableAdapteradapter=newCustomersTableAdapter(); bindingSource1.DataSource=adapter.GetData(); dataGridView1.DataSource=bindingSource1; } privatevoiddataGridView1_CellPainting(objectsender,DataGridViewCellPaintingEventArgse) { if(e.ColumnIndex<0) { e.Graphics.FillRectangle(Brushes.White,e.CellBounds); e.Handled=true; } } privatevoiddataGridView1_EditingControlShowing(objectsender,DataGridViewEditingControlShowingEventArgse) { if(dataGridView1.CurrentCell.ColumnIndex==1) { //e.CellStyle.BackColor=Color.FromName("window"); //DataGridViewComboBoxEditingControleditingControl=e.ControlasDataGridViewComboBoxEditingControl; DataGridViewTextBoxEditingControleditingControl=e.ControlasDataGridViewTextBoxEditingControl; editingControl.TextChanged+=newEventHandler(editingControl_TextChanged); } } voideditingControl_TextChanged(objectsender,EventArgse) { this.label1.Text=dataGridView1.CurrentCell.EditedFormattedValue.ToString(); } } }
希望本文所述对大家的C#程序设计有所帮助。