c# code for get datas from datagridview to combobox in .net



This is A C# Practice code:
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Linq;
        using System.Text;
        using System.Windows.Forms;
        using System.Data.SqlClient;
        namespace dataentry
        {
            public partial class DatatoCombobox : Form
            {
                public DatatoCombobox()
                {
                    InitializeComponent();
                }
               
                SqlConnection Connection = new SqlConnection("Data Source=.;Initial Catalog=DATAENTRY;Integrated Security=True;Pooling=False");
                private void DatatoCombobox_Load(object sender, EventArgs e)
                {

                }

                private void button9_Click(object sender, EventArgs e)
                {
                    SqlDataAdapter asdf = new SqlDataAdapter("select* from register",Connection);
                    DataTable SS = new DataTable();
                    asdf.Fill(SS);
                    dataGridView1.Rows.Clear();
                    foreach (DataRow ab in SS.Rows)
                    {
                        int num = dataGridView1.Rows.Add();
                        dataGridView1.Rows[num].Cells[0].Value = ab["NAME"].ToString();
                        dataGridView1.Rows[num].Cells[1].Value = ab["GENDER"].ToString();
                        dataGridView1.Rows[num].Cells[2].Value = ab["AGE"].ToString();
                        dataGridView1.Rows[num].Cells[3].Value = ab["SALARY"].ToString();
                        dataGridView1.Rows[num].Cells[4].Value = ab["STATUS"].ToString();
                    }
                }

                private void button1_Click(object sender, EventArgs e)
                {
                    comboBox1.Items.Clear();
                    foreach (DataGridViewRow datarow in dataGridView1.Rows)
                    {
                       
                    }
                    MessageBox.Show("Seccessfully Filled");

                    foreach (DataGridViewRow datarow in dataGridView1.Rows)
                    {
                        comboBox1.Items.Add(datarow.Cells[1].Value.ToString());
                    }

                }
            }
        }

Video For Result:



Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Facebook Comment