簡體   English   中英

如何檢查 DataGridView 單元格的類型?

[英]How to check the type of a DataGridView Cell?

我正在嘗試使用以下代碼檢查 DataGridView 單元格的單元格類型:

 Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
        If DataGridView1.Columns(e.ColumnIndex).Name = "ColCheck" Then
            Dim cell As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells("ColCheck")
            If cell Is DataGridViewCheckBoxCell Then

            End If

我得到DataGridViewCheckBoxCell是一種類型,不能用作表達式。

我在單元格點擊事件中嘗試了這個並且完美地工作:

Type str = dgv.Columns[dgv.SelectedCells[0].ColumnIndex].CellType;

如果您知道行和列索引,則另一種方法: dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType().Name

暫無
暫無

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

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