I just want to implement the custom fields in the show database tutorial and put some fields out of the display. This problem, but also small pondering a little ~ ~ ~ To achieve the following:
1: Add the number of columns you want to display in the DataGridView design interface and give the appropriate name:
2: Write the background code, the data source binding, binding is a DataTable. Then set the DataGridView property of the automatically created column to False.
View sourceprint?1 DataSet ds = Userinfobll.getalllist ();
2//Cancel dataGridView1 automatic creation column
3 This.datagridview1.autogeneratecolumns = false;
4 This.datagridview1.datasource = ds.tables[0];
3: The DataPropertyName property of the column added to the design interface points to the corresponding column to be displayed in the database, as follows
View sourceprint?1//Bind the DataPropertyName property of the custom column to the columns of the table in the database
2 this.datagridview1.columns["Column1"].datapropertyname = ds.tables[0].columns[0].tostring ();
3 this.datagridview1.columns["Column2"].datapropertyname = ds.tables[0].columns[1].tostring ();
4 this.datagridview1.columns["Column3"].datapropertyname = ds.tables[0].columns[3].tostring ();