views:

587

answers:

1

Hi

Trying to use a DataGridView like the old VB6 FlexGrid, and add the coloumns manually via addrow (built a Row containing TextCells) and my Coloums are all added (and display ok) but as soon as I try to add a row I get the message "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound." But for love nore god can I see a way of setting it as a unbound control (I've not set the datasourc to anything)

So two questions really,

  1. is there a better control to use ?
  2. is there way to set a DataGridView to be an unbound control

And a final third question

  1. How do you add row manually ?

Snippet of how I've done it do far

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)
+2  A: 

Is there a better control to use?

A bit subjective but I would say no. DataGridview is going to give you the most flexibility for building a grid like structure. It's extremely flexible and almost certainly fit your scenario

Is there a way to set a DataGridView to be an unbound control

Yes. Make sure the DataSource property is set to Nothing. This will force it into an unbound mode. As soon as you set this property to anything it will become a bound control

DataGridView1.DataSource = Nothing ' force unbound

How do you add a row manually?

Exactly as you've done. Once it's unbound this will work.

JaredPar
Ta, Code was exactly wright but once I'd stopped the datasource issue all feel into place, ta
spacemonkeys