微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

DataGridViewComboboxColumn 单元格值

如何解决DataGridViewComboboxColumn 单元格值

我有一个带有组合框列的数据网格视图。我想将列中的所有值与已选择的值相匹配。我有一个上下文菜单条,因此您可以右键单击单元格,然后更改整列。与此类似的问题有我无法理解或无法开始工作的提示和技巧。以下代码的结果,是否运行无误;但列单元格值不会以传递给它的值结束。我是 datagridviews 的新手,它们比我预期的要复杂。你知道我错过了什么吗?

Form Snapshot

vb.net
{Public Sub g_CMSFrmColmsDGVValForColumnClick(Sender As Object,e As ToolStripItemClickedEventArgs)
        'Creation of this context menu strip is above in sub new
        'Dim Item As ToolStripItem = e.ClickedItem       

        ' If the contextstrip button that was clicked is the first one("Val for Column")
        If e.ClickedItem Is g_CMSFrmColmsDGV.Items.Item(0) Then
            ' Get list of selected cells
            Dim SelectedCells As New List(Of DataGridViewCell)
            For Each SelCell As DataGridViewCell In g_FormColumns.DGV_Columns.SelectedCells : SelectedCells.Add(SelCell) : Next
            ' Exit sub if no cells are selected
            If SelectedCells.Count = 0 Then : MessageBox.Show("Please select at least one cell.") : Exit Sub : End If

            ' If more than one cell is selected sort through them.
            If SelectedCells.Count > 1 Then : CheckColumnDuplicates(SelectedCells) : End If


            If SelectedCells.Count = 1 Then
                ' Go through each row in the column and change the values to the selected cell value.
                For i As Integer = 0 To SelectedCells.Item(0).DataGridView.Rows.Count - 1
                    ' Do not replace the value of the row of the selected cell.
                    If i <> SelectedCells.Item(0).RowIndex Then
                        ' Change this cells value.
                        Dim ComboCell As DataGridViewComboBoxCell = g_FormColumns.DGV_Columns.Rows(i).Cells.Item(SelectedCells.Item(0).ColumnIndex)
                        ComboCell.Value = SelectedCells.Item(0).Value
                      
                        g_FormColumns.DGV_Columns.Refresh()
                    End If
                Next
            End If
        End If

    End Sub}

*更新 如果我点击列中的单元格,我想要的值就在那里。当我从单元格中单击时它就会消失。所以我认为该值已更改,但未显示更改。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。