Usage of ComboBox:
1.ComboBox bound DataTable
DataTable dt = _product. GetCode (Cbbcategory.text); // declaring a Datatabble object and assigning a value
ComboBox1. DataSource = DT; // Binding a DataTable
ComboBox1 . DisplayMember = dt. columns["code"]. ToString (); // set the columns for the DataTable to be displayed
2. Add directly using the Add ()
foreach (string in color) { ComboBox1.Items.Add (col);}
Usage of DataGridView:
1. Dynamically generate rows and columns and name the head of the Wardrobe column:
string[] colors = product. GetColor (code);//array of colors as rowsstring[] sizes = product. GetSize (code);//size array as column if(Colors = =NULL|| Sizes = =NULL)return;d Gvpurchase.columncount= sizes. Length;//set Number of columns for(inti =0; I < sizes. Length; i++) {Dgvpurchase.columns[i]. Name= Sizes[i];//loop to name a column header}dgvpurchase.rowcount= Colors. Length;//set Number of rows for(intj =0; J < Colors. Length; J + +) {Dgvpurchase.rows[j]. Headercell.value= Colors[j];//cycle to name a costume}
2. Insert an entire row of data into the DataGridView:
DataGridViewRow dr =NewDataGridViewRow ();//declaration LinesDr. Createcells (dgvproduct);d R. cells[0]. Value = strs[0];//adding elementsDr. cells[1]. Value = strs[1];d R. cells[2]. Value = strs[2];d R. cells[3]. Value = strs[3];d R. cells[4]. Value = strs[4];d R. cells[5]. Value = strs[5];d R. cells[6]. Value = strs[6];d gvProduct.Rows.Add (DR);//Insert Row
3. Traverse DataGridView Similarly
foreach inch datagridview1.rows) { for (int i=0; i<dr. cells.count;i++) { str[i]=dr[i]. Value.tostring (); // extracting elements }}
"Bi-set" on the use of ComboBox and DataGridView