none
how i can not load comboboxcell into datagridview in vb 2010

    Question

  • Hi friends,

    I have a datagridview on a form so that, I want populate 'serial' field of 'hesab_moin' table into datagridviewcomboboxcell witch load into 'id_moin' field of 'sanad_hesabdari.

    Accounting_document_Load subrutin working good, but Sub_Get_Accounts_example()subrutin is not load datagridviewcomboboxcell.

    This is my code :

    Private Sub Accounting_document_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Try

                Sub_Get_Accounts_example()

                sanad_hesabdari_load_example()

               

            Catch ex As Exception

                MsgBox(ex.Message)

            End Try

        End Sub

       

    Private Sub Sub_Get_Accounts_example()

            Dim Da As SqlDataAdapter

            Try

                con.Open()                          'open connection to sql 

                dt = New DataTable

                Da = New SqlDataAdapter("SELECT serial,moin_name From hesab_moin order by id_moin", con)

                Da.Fill(dt)

                ComboBox2.DataSource = dt

                ComboBox2.DisplayMember = "serial"

                ComboBox2.ValueMember = "moin_name"

                con.Close()

            Catch ex As Exception

                'Me.Message.Text = ex.Message 

            End Try

        End Sub

        Private Sub sanad_hesabdari_load_example()

            Dim dt_edit As New DataTable

            Dim CBCell As DataGridViewComboBoxCell

            Dim Da As SqlDataAdapter

            Dim SqlQuery As String

            SqlQuery = "select id_moin,kod_tafzil,sathe_5,sathe_6,sharh,bed, ,arz_ from sanad_hesabdari"

            con.Open()

            Da = New SqlDataAdapter(SqlQuery, con)

            Da.Fill(dt_edit)

            For i = 0 To Dt_Edit.Rows.Count - 1

                Try

                    DataGridView1.Rows.Add(dt_edit.Rows.Count)

                    'DataGridView1.Rows(i).Cells("id_moin").Value = dt_edit.Rows(i)("serial").ToString

                    CBCell = DataGridView1.Rows(0).Cells("combobox2")

                    CBCell.Items.Add(dt_edit.Rows(i)("id_moin").ToString)

                Catch ex As Exception

                End Try

            Next

            Try

                DataGridView1.Visible = True

                DataGridView1.DataSource = dt_edit

                con.Close()

            Catch ex As Exception

            End Try

        End Sub

    Pls help me.

    Best regards.

    Saturday, November 09, 2013 9:53 AM

Answers

  • Hi,

    >>Sub_Get_Accounts_example()subrutin is not load datagridviewcomboboxcell.

    Is the type of the "combobox2 is DataGridViewComboBoxColumn?

    For my understanding ,You want populate 'serial'field of 'hesab_moin'table into datagridviewcomboboxcell,I suggest you to create DataGridViewComboBoxColumn,and banding datasource into DataGridViewComboBoxColumn, then add a column in DataGridView,You can refer the link in MSDN:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn(v=vs.110).aspx

    And if you just want fill a ComboBoxCell ,You can just use DataGridViewComboBoxCell.Items.add  populate the datagridviewcomboboxcell.

    Regards& Thanks,

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 13, 2013 1:19 AM

All replies