标题:如何读取这个datagridview中combobox的选定值
取消只看楼主
snapy2002
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-10-19
 问题点数:0 回复次数:0 
如何读取这个datagridview中combobox的选定值
我将一个checkedlistbox中选中的值添加到另一个datagridview的combobox中。

现要读取这个datagridview中combobox的选定值,红字部分该怎么写?
因为combobox是用代码插进去的,所以我用DataGridView3.Rows(j).Cells(x).Value读取失败,找不到是第几列。
虽然我设的column.DisplayIndex = 2,但实际读取时不是cells(2)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
代码如下:
 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim tbl As New DataTable("tbl")
        tbl.Columns.Add("Display", GetType(String))
        tbl.Columns.Add("Value", GetType(Integer))
        For i = 0 To rs - 1
            tbl.Rows.Add(CheckedListBox2.CheckedItems.Item(i).ToString, i)
        Next

        Dim column As New DataGridViewComboBoxColumn()
        column.DataPropertyName = "BZFS"
        column.DataSource = tbl
        column.ValueMember = "Value"
        column.DisplayMember = "Display"
        column.HeaderText = "包装方式"
        column.DisplayIndex = 2

        DataGridView3.Columns.Add(column)
 End Sub

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim j As Integer = 0
            For j = 0 To DataGridView3.Rows.Count - 1
                zzz = New String(DataGridView3.Rows(j).Cells(2).Value)
                If zzz = String.Empty Then
                Else
                    Dim dcmd As New SqlCommand("insert into 工时成本 (包装单号,员工编号,包装方式,数量) values(@bno,@yno,@fs,@sl)", conn)
                    dcmd.Parameters.AddWithValue("@bno", nn)
                    dcmd.Parameters.AddWithValue("@yno", DataGridView3.Rows(j).Cells(0).Value)
                    dcmd.Parameters.AddWithValue("@fs", ????????)  '将combobox的选定值赋值给@fs
                    dcmd.Parameters.AddWithValue("@sl", DataGridView3.Rows(j).Cells(2).Value)
                    Try
                        dcmd.ExecuteNonQuery()
                        DataGridView3.Rows(j).Cells(2).Value = ""
                    Catch ex As SqlException
                        MsgBox("工时成本写入失败")
                    End Try
                    zzz = ""
                End If
            Next
 End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

搜索更多相关主题的帖子: combobox datagridview 
2010-10-19 14:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-323339-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.608775 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved