I have a datagridview bound to a datatable and it works great. However, when I try to programmatically change the datasource property to a different existing table, I get a blank datagridview with no cells. Although I have tried many bits of code to remedy the problem, this is the one that I felt should do the trick:

dgvThresholds.DataSource = SquirrelDataSet.Tables("Threshold market 12")
ThresholdMarketTableListTableAdapter.Update(SquirrelDataSet.Tables("Threshold market 12"))
dgvThresholds.DataSource = ThresholdMarketDefaultBindingSource
dgvThresholds.Refresh()

Any advice on how to get this thing to work? Seems simple...

Recommended Answers

All 3 Replies

Check and see if your datatable is still populated after your update...

Okay, this is weird. I had to remove line 2 to get the code to run. It would bug out on that line. So I tried:

dgvThresholds.DataSource = SquirrelDataSet.Tables("Threshold market 12")
dgvThresholds.DataSource = ThresholdMarketDefaultBindingSource
dgvThresholds.Refresh()
MsgBox(SquirrelDataSet.Tables("Threshold market 12").Rows(0).Item(1))

I must have a syntax issue with the last line because it bugs out on that as well. Any ideas?

Okay, here is what I came up with:

Dim bindingSource As BindingSource
bindingSource = New BindingSource()
bindingSource.DataSource = Threshold_market_6TableAdapter.GetData
dgvThresholds.DataSource = bindingSource
bindingSource.ResetBindings(False)

The problem now is that the third line is not able to be set to the value the user chooses in the combobox. In other words, I want the bindingsource.datasource property to be set to Threshold_market_6TableAdapter if that's what the user chose in the combobox, but Threshold_market_2TableAdapter if that is what they chose. I tried setting the value to a variable and useing bindingSource.DataSource = VariableName and even bindingSource.DataSource = VariableName.GetData but neither will cause the datagridview to populate. Suggestions?

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.