Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to add multiple Datagridviewcomboboxcolumn in datagrid in win application and to update those columns also from the value.


I have added the combobox column by setting different datatable as datasource but when i change the value of one combobox then all the combobox value changes

does anyone one has the code or application to help in this.
Posted
Comments
Kschuler 20-Dec-10 13:54pm    
Could you post the relevant code you are using, please.
nitin_ion 20-Dec-10 14:37pm    
code is added

VB
Public Class Form1
    Dim mcn As MySqlConnection
    Dim mcm As MySqlCommand
    Dim mda As New MySqlDataAdapter
    Dim mdt As New DataTable
    Dim mds As New DataSet
    Dim str As String
    Dim value As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        str = "server=localhost;uid=root;pwd=bss;database=cdetail"
        mcn = New MySqlConnection
        mcn.ConnectionString = str
        mcn.Open()
        FillGridView()

        End Sub

    Private Sub FillGridView()

        '--- Adding the values into the combo box through the List---
        Dim cmbOpt1 As DataGridViewComboBoxColumn = CType(DataGridView1.Columns("loc"), DataGridViewComboBoxColumn)
        Dim cmbOpt2 As DataGridViewComboBoxColumn = CType(DataGridView1.Columns("PRODUCT"), DataGridViewComboBoxColumn)
        Try

            str = "select Name,fullname from others order by Name"
            mda = New MySqlDataAdapter(str, mcn)
            Dim mdt1 As New DataTable
            mda.Fill(mdt1)
            'If loc.DataSource Is Nothing Then
            cmbOpt1.DataSource = mdt1
            cmbOpt1.DisplayMember = "Name"
            cmbOpt1.ValueMember = "fullname"

            Dim str2 As String
            Dim mda1 As New MySqlDataAdapter
            Dim mdt2 As New DataTable
            str2 = "select productname,fullname from product order by productname"
            mda = New MySqlDataAdapter(str2, mcn)
            mda.Fill(mdt2)
            cmbOpt2.DataSource = mdt2
            cmbOpt2.DisplayMember = "productname"
            cmbOpt2.ValueMember = "fullname"

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

End Class
 
Share this answer
 
Comments
Toniyo Jackson 21-Dec-10 4:39am    
Dont add your question here. You can add in question by clicking Improve Answer.
VB
Public SqlCon As New System.Data.SqlClient.SqlConnection("server=??? Servername or . for local??;user id=???UserName???;pwd=???Password???;data source=???Server Name or .???;database=?? Database name ???")
Dim tbl As New DataTable
Dim dvw As DataView
Dim b As Boolean
Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Personalinfo", sqlcon)
sqlcon.Open()
Dim sdr As SqlClient.SqlDataReader = cmd.ExecuteReader
Dim fc As Integer
While (sdr.Read)
    'populating columns
    If Not b Then
        For fc = 0 To sdr.FieldCount - 1
            tbl.Columns.Add(sdr.GetName(fc))
        Next
        b = True
    End If
    'populating rows
    Dim row As DataRow = tbl.NewRow
    For fc = 0 To sdr.FieldCount - 1
        row(fc) = sdr(fc)
    Next
    tbl.Rows.Add(row)
End While
dvw = New DataView(tbl)
Me.dgrPersonalInfo.DataSource = dvw
sqlcon.Close()
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900