如何从DataGridviewComboboxColumn中的DataSource获取值ID

时间:2016-05-12 18:43:53

标签: vb.net datagridview

我有一个像这样的子:

git clone git://git.qemu-project.org/qemu.git

正如您在DataGridViewComboBoxColum中看到的数据集:

Public Sub Populate(ByVal DataGridView As DataGridView, ByVal bs As BindingSource, ByRef bsPositions As BindingSource)

    Dim ds As New DataSet

    Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=demo.mdb;")

                    Dim da As New OleDbDataAdapter("SELECT DISTINCT BIDUSER_PI_CAB_TEMP.MEIO, BIDUSER_SUBMEIO.DS_SUBMEIO " & _
                                       " FROM (BIDUSER_PI_CAB_TEMP LEFT JOIN BIDUSER_SUBMEIO ON " & _
                                       " BIDUSER_PI_CAB_TEMP.ID_SUBMEIO = BIDUSER_SUBMEIO.ID_SUBMEIO) " & _                                           " LEFT JOIN BIDUSER_MEIO ON BIDUSER_SUBMEIO.ID_MEIO = BIDUSER_MEIO.ID_MEIO " & _
                                       " WHERE (((BIDUSER_PI_CAB_TEMP.STATUS_PI)<>'CANCELADO'))", cn)

        da.Fill(ds, "Names")
        da = New OleDbDataAdapter("select ID_SUBMEIO,DS_SUBMEIO from biduser_SUBMEIO " & _
                                       "order by DS_SUBMEIO", cn)
        da.Fill(ds, "PositionType")

    End Using

    Dim PeopleNamesColumn As New DataGridViewTextBoxColumn With
        {
            .DataPropertyName = "MEIO",
            .HeaderText = "MEIO"
        }

    bsPositions.DataSource = ds.Tables("PositionType")


    Dim ContactPositionColumn As New DataGridViewComboBoxColumn With
        {
            .DataPropertyName = "DS_SUBMEIO",
            .DataSource = bsPositions,
            .DisplayMember = "DS_submeio",
            .DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
            .Name = "SubMeio",
            .HeaderText = "SubMeio",
            .SortMode = DataGridViewColumnSortMode.Automatic,
            .ValueMember = "DS_SUBMEIO"
        }



    DataGridView.AutoGenerateColumns = False

    DataGridView.Columns.AddRange(New DataGridViewColumn() {PeopleNamesColumn, ContactPositionColumn})

    ds.Tables("Names").AcceptChanges()

    bs.DataSource = ds.Tables("Names")
    DataGridView.DataSource = bs
    DataGridView.ExpandColumns()

End Sub

当用户在Combobox中选择一个值,在Gridview ComboBox列中,或者直接从DataGridViewComboBoxColum的Datasource中选择一个值时,我需要获取ID_SUBMEIO的值。你知道我是怎么做到的吗?

0 个答案:

没有答案