簡體   English   中英

從 dataGridView 單元格中的組合框中選擇一個值時面臨問題,它必須用同一數據單元格中的文本框替換

[英]facing issue when select a value from combobox in dataGridView cell it have to replace with textBox in same datacell

下面是我的組合框值填充函數

   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

下面的功能是從組合框中選擇值后,我們必須將該組合框更改為同一單元格中的文本框

    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

但是組合框沒有替換為文本框。

得到答復非常感謝!!!

這是非常錯誤的:

DataGridView1.CurrentCell.Value = Datas

您正在創建一個新單元格,然后嘗試將其分配給現有單元格的Value 這有什么意義? 你不能在一個單元格內有一個單元格,你也不能神奇地改變一個單元格的類型。 如果您想要不同類型的單元格,則需要用該類型的新單元格替換現有單元格:

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

DataGridView1(columnIndex, rowIndex) = Datas

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM