0

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.

6
Contributors
5
Replies
26
Views
9 Years
Discussion Span
Last Post by concepcionmark
Featured 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 … Read More

1

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
CONTCOLUMN()
Else
MsgBox("YOU ARE IN THIS PHASE")
End If
End Sub

0

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

0

try editing this part,

Dim contcolumn As New DataGridViewTextBoxColumn

to

Dim contcolumn As New DataGridViewButtonColumn

hope this helps.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.