面对问题时,从datagridview单元格中的combobox中选择一个值时,必须在同一datacell中替换为文本框

发布于 2025-02-11 12:23:30 字数 646 浏览 2 评论 0原文

下面是我的ComboBox值源函数

   If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
        Dim row1 = New ArrayList()
        row1.AddRange(New Integer() {1, 2})
        p.Items.AddRange(row1.ToArray())
        DataGridView1(e.ColumnIndex, e.RowIndex) = p
    End If

下面的功能是在选择ComboBox的值之后,我们必须将ComboBox更改为同一单元格中的TextBox

    Dim combo1 As ComboBox = CType(sender, ComboBox)
    If combo1.SelectedIndex = 0 Then
        Dim Datas As New DataGridViewTextBoxCell
        Datas.Value = "S"
        DataGridView1.CurrentCell.Value = Datas
    End If

,但ComboBox未替换为文本框。

得到答复是高度赞赏的!!!

below is my comboBox value populate function

   If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
        Dim row1 = New ArrayList()
        row1.AddRange(New Integer() {1, 2})
        p.Items.AddRange(row1.ToArray())
        DataGridView1(e.ColumnIndex, e.RowIndex) = p
    End If

below function is for after selecting value from comboBox, we have to change that combobox to textbox in same cell

    Dim combo1 As ComboBox = CType(sender, ComboBox)
    If combo1.SelectedIndex = 0 Then
        Dim Datas As New DataGridViewTextBoxCell
        Datas.Value = "S"
        DataGridView1.CurrentCell.Value = Datas
    End If

but comboBox have not replacing to textBox.

getting reply is highly appreciated!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰認得朕 2025-02-18 12:23:30

这是如此错误:

DataGridView1.CurrentCell.Value = Datas

您正在创建一个新单元格,然后尝试将其分配给现有单元格的value。这有什么意义?您不能在单元格内有一个单元格,也不能神奇地更改单元格的类型。如果您想要一个不同类型的单元格,则需要用该类型的新单元格代替现有单元格:

Dim currentCellAddress = DataGridView1.CurrentCellAddress
Dim columnIndex = currentCellAddress.X
Dim rowIndex = currentCellAddress.Y

DataGridView1(columnIndex, rowIndex) = Datas

This is so wrong:

DataGridView1.CurrentCell.Value = Datas

You are creating a new cell and then trying to assign that to the Value of the existing cell. How does that make sense? You can't have a cell inside a cell and you can't magically change the type of a cell. If you want a cell of a different type then you need to replace the existing cell with a new cell of that type:

Dim currentCellAddress = DataGridView1.CurrentCellAddress
Dim columnIndex = currentCellAddress.X
Dim rowIndex = currentCellAddress.Y

DataGridView1(columnIndex, rowIndex) = Datas
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文