how to fill datagridview combobox column in c#
  • how to fill datagridviewcomboboxcolumn in c# from code on form_load event.
  • 2 Comments sorted by
  • You rowdatabound event to fill combobox inside gridview . i have code but you will get your concept.

    For Each row In GridView1.Rows
    Dim taskno As Label = CType(row.FindControl("lbltaskno"), Label)
    Dim mydropdown As DropDownList = CType(row.FindControl("DropDownList1"), DropDownList)
    QRY = "select Attachment.AttachTask from Attachment join TaskAssignment on Attachmentno=TaskUniqueNo where Attachmentno='" & taskno.Text & "'"
    Dim i As Integer
    dtTaskAssig = objtms.GetAdapter(QRY)
    For i = 0 To dtTaskAssig.Rows.Count - 1
    mydropdown.Items.Add(New ListItem(dtTaskAssig.Rows(i)(0).ToString))
    for further details and related topics
  • Vote Up0Vote Down ithackerithacker
    117.50 Karma Accepted Answer
    you can get data from database to datatable and then attach it to DataGridviewComboBoxColumn like this.

    SqlConnection objCon = new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=YourDatabaseName;Integrated Security=True");

                SqlCommand objCmd = new SqlCommand("select Column1,Column2 from TableName", objCon);

                SqlDataAdapter objDA = new SqlDataAdapter(objCmd);

                objDA.SelectCommand.CommandText = objCmd.CommandText.ToString();
                DataTable dt = new DataTable();

                DataGridViewComboBoColumnName.DataSource = dt;

        //this column1 will display as text
                DataGridViewComboBoColumnName.DisplayMember = "Column1";    

        //this column2 will use as back end value who can you use in selectedValue property
                DataGridViewComboBoColumnName.ValueMember = "Column2";       

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook


Popular Posts of the Week

    Optimum Creative