I am getting this message:
value of type "System.data.datacolumn" cannot be converted to "System.windows.forms.datagridviewcolumn"
when I am trying to add a column to the dgv

Dim dtcCheck As New DataColumn("Select")
        dtcCheck.DataType = System.Type.GetType("System.Boolean")
        dtcCheck.DefaultValue = False
        Dim sa As New SqlDataAdapter("SELECT * FROM therapy", myconnection1)
        sa.Fill(ds, "Therapy")
        dgvther.DataSource = ds.Tables("Therapy")
        dgvther.Columns.Add(dtcCheck) '<<Error is the dtcCheck

Any help on this will be greatly appreciated.

Recommended Answers

All 5 Replies

Try this code mentioned below to add column to datagrid view
Public strTest As String
Private Sub CONTCOLUMN()

Dim contcolumn As New DataGridViewTextBoxColumn

With contcolumn
.HeaderText = strTest
.Name = strTest

End With

DataGridView1.Columns.Insert(1, contcolumn)
End Sub
Public Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CB.SelectedIndexChanged

strTest = CB.SelectedItem
If strTest = "City" Then
End If
End Sub

Thank you Alekhan.

Thank you so much Brow ... ^_^

I have the same problem but with DataGridViewTextBoxColumn. I've tried the solution above yet didn't work. What am I supposed to do? :(

try editing this part,

Dim contcolumn As New DataGridViewTextBoxColumn


Dim contcolumn As New DataGridViewButtonColumn

hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.