SamuraiJack
SamuraiJack

Reputation: 5549

How to check the type of a DataGridView Cell?

I am trying to check the cell type of a DataGridView Cell by using following code:

 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

I am getting DataGridViewCheckBoxCell is a type and can not be used as an expression.

Upvotes: 2

Views: 7441

Answers (2)

marky
marky

Reputation: 5068

Another method if you know the row and column indexes: dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType().Name

Upvotes: 1

Shamseer K
Shamseer K

Reputation: 5301

i tried this in cell click event and works perfectly :

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

Upvotes: 2

Related Questions