To be a project, you need to dynamize the Checkbox control in DataGrid, even beginner rookie, WebForm knows with template column, and it will be Winform.
So I look at the Winform's template column everywhere, and then gradually understand DataGridTableStyle, ColumnStyle ... Since I have a mediocrity, spending a bit of a long time in half a day, the following experience summary, please don't laugh, but welcome criticism ......
I think the easiest way to do even the difference, in fact, there are many ways to load the control, even two kinds of choices, easy to understand:
The first:
WindowsDisplayBLL MYWDB = New WindowsDisplayBLL ();
DataTable mydt = mywdb.displaymedicamentDataSet.tables [0]; // Easy to use the table you want to use in the DataSet for easy operation
// Create a checkbox column, headerText is "Select", the type is Boolean, the default value is false, then add to mydt table
// This definition is to ensure that the data can be displayed simultaneously with the data when displaying the DataGrid.
Not you click on the mouse click to display
Datacolumn DCCHECK = New Datacolumn ("Select");
DcCheck.DataType = type.gettype ("System.Boolean");
DCCHECK.DEFAULTVALUE = FALSE;
Mydt.columns.add (dccheck);
// This will have 5 fields in the table, plus this newly added checkbox into 6 fields, determine the number of DataGridTableStyle defined according to the number of fields, so that all fields in your table are fully displayed
// Add DataGridTableStyle, pay attention to the correspondence with Table!
DataGridTableStyle DGStyle = New DataGridTableLeStyle ();
DGStyle.mappingname = mydt.tablename;
DataGridColumnStyle DG_ID = New DataGridTextBoxColumn ();
DG_ID.MAPPINGNAME = "m_id";
DG_ID.Headertext = "Number";
DG_ID.WIDTH = 50;
DataGridColumnStyle DG_TYPE = New DataGridTextBoxColumn ();
DG_TYPE.MAPPINGNAME = "M_TYPE";
DG_TYPE.HEADERTEXT = "Type";
DG_TYPE.WIDTH = 100;
DataGridColumnStyle DG_NAME = New DataGridTextBoxColumn ();
DG_NAME.MAPPINGNAME = "m_name";
DG_NAME.HEADERTEXT = "Name";
DG_ID.WIDTH = 60;
DataGridColumnStyle DG_QID = New DataGridTextBoxColumn ();
DG_QID.MAppingName = "m_qid";
DG_QID.Headertext = "Measurement ID";
DG_QID.Width = 60;
DataGridColumnStyle DG_Unit = New DataGridTextBoxColumn (); DG_UNIT.MAPPINGNAME = "M_Unit";
DG_Unit.Headertext = "Metering Unit ID";
DG_UNIT.WIDTH = 50;
DataGridColumnStyle DG_BOOL = New DataGridBoolColumn (); // The BOOL type defined here is the location of Checkbox
DG_BOOL.MAPPINGNAME = "Select";
DG_BOOL.HEADERTEXT = "Boolean";
DG_BOOL.WIDTH = 50;
DataGridColumnStyle [] DGCOLUMN = New DataGridColumnStyle [6] {DG_ID, DG_TYPE, DG_NAME, DG_QID, DG_UNIT, DG_BOOL}; // The number of DGCOLUMNs here is corresponding to DataGridColumnStyle defined above.
DGStyle.gridcolumnStyles.Addrange (DGColumn);
DGMedicamentList.TablesTyles.Add (DGStyle);
DGMedicamentList.DataSource = mydt;
Second:
WindowsDisplayBLL MYWDB = New WindowsDisplayBLL ();
DataTable mydt = mywdb.displaymedicamentDataSet.tables [0];
/ / I read this annotation here, because this is the first method, the rest of the whole! !
// datacolumn dcheck = new datacolumn ("Select");
// dccheck.datatype = type.gettype ("system.string");
// DCCHECK.DEFAULTVALUE = "Button";
// mydt.column.add (dccheck);
// Add DataGridTableStyle, pay attention to the correspondence with Table!
DataGridTableStyle DGStyle = New DataGridTableLeStyle ();
DGStyle.mappingname = mydt.tablename;
DataGridColumnStyle DG_ID = New DataGridTextBoxColumn ();
DG_ID.MAPPINGNAME = "m_id";
DG_ID.Headertext = "Number";
DG_ID.WIDTH = 50;
DataGridColumnStyle DG_TYPE = New DataGridTextBoxColumn ();
DG_TYPE.MAPPINGNAME = "M_TYPE";
DG_TYPE.HEADERTEXT = "Type";
DG_TYPE.WIDTH = 100;
DataGridColumnStyle DG_NAME = New DataGridTextBoxColumn ();
DG_NAME.MAPPINGNAME = "m_name";
DG_NAME.HEADERTEXT = "Name";
DG_ID.WIDTH = 60;
DataGridColumnStyle DG_QID = New DataGridTextBoxColumn (); DG_QID.MAppingName = "m_qid";
DG_QID.Headertext = "Measurement ID";
DG_QID.Width = 60;
DataGridColumnStyle DG_Unit = New DataGridTextBoxColumn ();
DG_Unit.mappingname = "m_unit";
DG_Unit.Headertext = "Metering Unit ID";
DG_UNIT.WIDTH = 50;
DataGridColumnStyle DG_BOOL = New DataGridTextBoxColumn ();
DG_BOOL.MAPPINGNAME = "Select";
DG_BOOL.HEADERTEXT = "Button";
DG_BOOL.WIDTH = 50;
DataGridColumnStyle [] DGCOLUMN = New DataGridColumnStyle [6] {DG_ID, DG_TYPE, DG_NAME, DG_QID, DG_UNIT, DG_BOOL};
DGStyle.gridcolumnStyles.Addrange (DGColumn);
DGMedicamentList.TablesTyles.Add (DGStyle);
DGMedicamentList.DataSource = mydt;
/ / This is the essence of the second method! ! Difference to the first method, this method is
You have to click on the mouse to click.
DataGridTextBoxColumn DGTBC = (DataGridTextBoxColumn) DGMedicamentList.tableStyles [0] .gridcolumnstyles [0]; // The number defined here
Checkbox mycb = new checkbox ();
Mycb.dock = dockstyle.fill;
Mycb.text = "";
DGTBC.TEXTBOX.CONTROLS.ADD (MyCB);