Click here to Skip to main content
Sign Up to vote bad
good
See more: VB.NET
I have 10 columns in datagridview out of which last 3 columns(caste,prof,degree) are combobox. My task is if database have value for these 3 fields,it should display in combobox of grid else empty combobox should be added for user to select value.Code to add combobox column is below.Can any1 please help me.
Dim con As OdbcConnection = New OdbcConnection
        sql = "Select Description from Category where Catgry = 1"
        con.ConnectionString = connstring
        If con.State = ConnectionState.Open Then con.Close()
        con.Open()
        Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, con)
        da.Fill(ds, "Caste")
 
        With col_Caste
            .Name = "Caste"
            .HeaderText = "Caste"
            .DataSource = ds.Tables("Caste")
            .DisplayMember = "Description"
            .ReadOnly = False
        End With
 
        dgvUserDetails.Columns.Add(col_Caste)
Posted 30 Dec '12 - 19:53
Edited 30 Dec '12 - 19:54

Comments
prashant patil 4987 - 31 Dec '12 - 1:57
you want to display all these last three columns values in Combobox or What????
Rachna0309 - 31 Dec '12 - 1:58
yes in combobox..
prashant patil 4987 - 31 Dec '12 - 2:07
ok
Rachna0309 - 31 Dec '12 - 2:26
Do you have solution for this?
prashant patil 4987 - 31 Dec '12 - 2:33
hey rachhna for this first you have to find combobox control from datagridview then set the datasource for combo box with binbing above three columns.
Rachna0309 - 31 Dec '12 - 2:34
can you put down code for this?
prashant patil 4987 - 31 Dec '12 - 2:39
are you use DataGridViewComboBoxCell or seperate Asp.net Combobox Control.???
Rachna0309 - 31 Dec '12 - 2:41
datagridviewcombobox column in vb.net desktop application.
prashant patil 4987 - 31 Dec '12 - 2:42
then try to use like this Dim cmb As New DataGridViewComboBoxColumn() cmb.HeaderText = "Select Data" cmb.Name = "cmb" cmb.MaxDropDownItems = 4 cmb.Items.Add("True") cmb.Items.Add("False") DataGridView1.Columns.Add(cmb)
Rachna0309 - 31 Dec '12 - 3:00
This will add comboboxcolumn which I have already done.I want to get value in combobox if database table contains records for these columns.
prashant patil 4987 - 31 Dec '12 - 3:42
ok try this... Dim t = DirectCast(dgv1.Rows(dgv1.CurrentCell.RowIndex).Cells(3), DataGridViewComboBoxCell) t.DataSource = "your Dataset for fillin combobox" t.DisplayMember = "col1" t.ValueMember = "col2" t.Value = 0

1 solution

Add in a item template in your gridview.
Once that is done you would get options to link them to sql datasources or other sources to get the records.
Pass in a sql select command. if it doesnt return anything, then the combobox would be empty
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Aarti Meswania 210
4 Maciej Los 200
0 Sergey Alexandrovich Kryukov 8,953
1 OriginalGriff 7,134
2 CPallini 3,758
3 Rohan Leuva 3,036
4 Maciej Los 2,488


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid