C # How to bind a custom ComboBox to a cell in a dview

Source: Internet
Author: User

Use the cellendedit event to trigger the function to respond to changes in cell values.
To bind combbox, I define the column of the datagridview dview as the datagridviewcomboboxcolumn, and then forcibly convert the specified cell to the datagridviewcomboboxcell to bind the data.

 

// You can add the following code to the editingcontrolshowing event of the datagridview to add an event to your comboxbox to handle binding issues in this event.
Private void variouscostdgv3_editingcontrolshowing (Object sender, datagridvieweditingcontrolshowingeventargs E)
{
If (E. Control. GetType (). Equals (typeof (datagridviewcomboboxeditingcontrol )))
{
Datagridviewcomboboxeditingcontrol editingcontrol = E. Control as datagridviewcomboboxeditingcontrol;
Editingcontrol. dropdownclosed + = new eventhandler (editingcontrol_dropdownclosed );
}
}

// Then, bind it to the event handler function. In this code, I dynamically change the value of a cell and modify the alignment mode. You can bind a new cell.

Private void editingcontrol_dropdownclosed (Object sender, eventargs E)
{
Datagridviewcomboboxeditingcontrol CTL = sender as datagridviewcomboboxeditingcontrol;
Datarowview DRV = This. variouscostdgv3.rows [CTL. editingcontrolrowindex]. databounditem as datarowview;
DRV ["unit_name"] = CTL. text;
DRV ["various_cost_unit"] = commondatamanager. getchargeunitdata (). getcd (CTL. Text );
If (commondatamanager. getchargeunitdata (). getcd (CTL. Text). Equals (estimatecommon. charge_unit_all ))
{
DRV ["Number"] = "-";
DRV ["lele_num"] = 1;
This. variouscostdgv3 ["numbercol3", CTL. editingcontrolrowindex]. readonly = true;
This. variouscostdgv3 ["numbercol3", CTL. editingcontrolrowindex]. style. Alignment = maid. middlecenter;
}
Else
{
DRV ["Number"] = DRV ["people_num"];
If (estimatecommon. estimate_type_real.equals (mdsforinternal. Tables ["cz_estimate"]. Rows [0] ["estimate_type"]. tostring ()))
{
This. variouscostdgv3 ["numbercol3", CTL. editingcontrolrowindex]. readonly = false;
}
This. variouscostdgv3 ["numbercol3", CTL. editingcontrolrowindex]. style. Alignment = maid. middleright;
}
This. variouscostdgv3.refresh ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.