0
votes

I load data from an XML to a dataset then I use the dataset to populate my datagridview. By doing that my DGV is getting bound to the dataset. Now I am getting the following error: 'RowCount property cannot be set on a data-bound DataGridView control.'

is there anyway to make my DGV "unbound" again to prevent these errors? or is there another way to fix this?

1
If you set the DataSource then the grid is bound. If you don't want the grid to be bound then don't set the DataSource, but that means that you have to create columns and rows and add all the data yourself. - jmcilhinney
so If i get this right instead of using: DGV.DataSource = Dataset.Tables("table1") I use: DGV(0, 0).Value = Dataset.Tables("table1").Rows(0).Item(0) - Fyer-Zero
Not just that. That second line of code sets the Value of a specific cell so you would have had to add at least one column and one row first to be able to do that. You would normally add the columns first and then add the rows and data at the same time, but you don't have to. I'm sure that you can find plenty of examples of populating a DataGridView with a web search. - jmcilhinney
I know that, I already got my columns set and will ofcourse add rows if needed. but just wanted to know if the line I just posted gets the value from the dataset and puts it in the specified cell. - Fyer-Zero

1 Answers

0
votes

Thanks for the help jmcilhinney, here the solution I ended up using

Do While i < Dataset.Tables("table1").Rows.Count
            If i = DGV.RowCount Then
                DGV.Rows.Add()
            End If
            c = 0
            Do While c < Dataset.Tables("table1").Columns.Count
                DGV.Rows(i).Cells(c).Value = Dataset.Tables("table1").Rows(i).Item(c)
                c = c + 1
            Loop
            i = i + 1
        Loop