"Bi-set" on the use of ComboBox and DataGridView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.