Private Dataset getDataSet () {string info = String.empty;
ERP.DEPARTMENTS D = New WindowsApplication1.erp.Departments (); DataSet DS = D.QueryAllDepartmentsIndataset (OUT INFO);
Return DS;
Private void initializedataGrid () {dataGridtableStyle myTableStyle = new DataGridtableStyle (); mytablestyle.mappingname = "departments";
// Create three DataGridColumnStyle DataGridColumnStyle myColumnStyle1 = new DataGridTextBoxColumn (); myColumnStyle1.MappingName = "ID"; myColumnStyle1.HeaderText = "No"; myColumnStyle1.Width = 35;
DataGridColumnStyle mycolumnStyle2 = new DataGridTextBoxColumn (); mycolumnstyle2.mappingname = "name"; mycolumnstyle2.Headertext = "name"; mycolumnstyle2.width = 80;
DataGridColumnStyle myColumnStyle3 = new DataGridTextBoxColumn (); myColumnStyle3.MappingName = "Description"; myColumnStyle3.HeaderText = "Notes"; myColumnStyle3.Width = 80;
// add the three ColumnStyle to TableStyle myTableStyle.GridColumnStyles.Add (myColumnStyle1); myTableStyle.GridColumnStyles.Add (myColumnStyle2); myTableStyle.GridColumnStyles.Add (myColumnStyle3); // be added to the DataGrid TableStyle
DataGrid1.tables.clear ();
DataGrid1.tables.add (MyTables); DataGrid1.datasource = getDataSet ();
Here is to emphasize: myTableStyle.mappingName = "departments"; must be set; and the corresponding mycolumnStyle3.mappingName should correspond to the table field.
DiatAgrid1.tablesTyles.clear (); this sentence should be added; otherwise it will be prompted to load