欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#中datagridview的EditingControlShowing事件用法实例

程序员文章站 2023-12-01 16:17:28
本文实例讲述了c#中datagridview的editingcontrolshowing事件用法。分享给大家供大家参考。具体实现方法如下: using syste...

本文实例讲述了c#中datagridview的editingcontrolshowing事件用法。分享给大家供大家参考。具体实现方法如下:

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 form3 : form 
  { 
    public form3() 
    { 
      initializecomponent(); 
    } 
    private void form3_load(object sender, eventargs e) 
    { 
      customerstableadapter adapter = new customerstableadapter();
      bindingsource1.datasource = adapter.getdata(); 
      datagridview1.datasource = bindingsource1; 
    } 
    private void datagridview1_cellpainting(object sender, datagridviewcellpaintingeventargs e) 
    { 
      if (e.columnindex < 0) 
      { 
        e.graphics.fillrectangle(brushes.white, e.cellbounds); 
        e.handled = true; 
      } 
    } 
    private void datagridview1_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e) 
    { 
      if (datagridview1.currentcell.columnindex == 1) 
      { 
        //e.cellstyle.backcolor = color.fromname("window"); 
        //datagridviewcomboboxeditingcontrol editingcontrol = e.control as datagridviewcomboboxeditingcontrol; 
        datagridviewtextboxeditingcontrol editingcontrol = e.control as datagridviewtextboxeditingcontrol; 
        editingcontrol.textchanged += new eventhandler(editingcontrol_textchanged); 
      } 
    } 
    void editingcontrol_textchanged(object sender, eventargs e) 
    { 
      this.label1.text = datagridview1.currentcell.editedformattedvalue.tostring(); 
    } 
  } 
}

希望本文所述对大家的c#程序设计有所帮助。