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 ();
}