Recently, I am working on a small C # winform item. I used to add a new row to datawindow. the implementation method is to right-click the menu and a form is displayed. The new form has a dview, and the first column is a datagridviewcheckboxcolumn. the row of the selected checkbox must be added to the parent form data source. determine which selected
Foreach (maid DR in this. Maid)
{
Try
{
// Maid cbx = (maid) DR. cells [0];
// If (bool) cbx. formattedvalue)
If (dr. cells [0]. Selected)
{
Arrshiftcode. Add (dr. cells [1]. value );
Arrshiftgroup. Add (dr. cells [2]. value );
}
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}}
The above is written in this way at the beginning. It is found that only the last one is true, and the others are false. The following code is used to query the information:
Foreach (maid DR in this. Maid)
{
Try
{
Maid cbx = (maid) DR. cells [0];
If (bool) cbx. formattedvalue)
{
Arrshiftcode. Add (dr. cells [1]. value );
Arrshiftgroup. Add (dr. cells [2]. value );
}
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
}