DateGrid View - As and unBound control

Trying to use the DataGridView like the old VB6 FlexGrid and add coloumns manually via addrow (built a row containing TextCells) and my Coloums are added (and display fine) but as soon as I try to add a row I get the message "Rows cannot be programmatically added to the row collection of the DataGridView when the control is data bound. " But there is no god for love, can I see a way to set it as an unbound control (I didn't set datasourc for anything)

So there are actually two questions,

  • Is there a better control to use?
  • is there a way to set DataGridView as unbound control

And the last third question

  1. How do I add a line manually?

A fragment of how I did it is far away

Thanks in advance

                  Dim lRow As New DataGridViewRow

                    Dim lCell As New DataGridViewTextBoxCell
                    lCell.Value = "Cell 1"
                    lRow.Cells.Add(lCell)

                    lCell = DataGridViewTextBoxCell
                    lCell.Value = "Cell 2"
                    lRow.Cells.Add(lCell)

                    DataGridView1.Rows.Add(lRow)

      

+1


a source to share


1 answer


Is there a better control to use?

A bit subjective, but I would say no. The DataGridview will give you maximum flexibility for building a grid like structure. It's extremely flexible and will almost certainly suit your scenario.

Is there a way to set DataGridView as unbound control

Yes. Make sure the DataSource property is set to Nothing. This will cause it to be disabled. Once you set this property to anything, it becomes a bound control



DataGridView1.DataSource = Nothing ' force unbound

      

How do I add a line manually?

Exactly the way you did it. Once it's disabled, this will work.

+3


a source







All Articles