Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot bind to the property or column SelectionValue on the Datasource

Status
Not open for further replies.

assimang

Programmer
Mar 11, 2008
96
Hello everybody I have 3 radio buttons in a groupbox in a form. I have a piece of code:

Public Sub SettingsFillDataSetAndViewAndBindFields()
SettingsFrm.EasyLvl.DataBindings.Clear()
SettingsFrm.IntermediateLvl.DataBindings.Clear()
SettingsFrm.AdvancedLvl.DataBindings.Clear()
SettingsAccAdapter = New SqlDataAdapter("select SelectionValue from settings", MyConn)
DsSettingsAcc = New DataSet
SettingsAccAdapter.Fill(DsSettingsAcc, "AccSettins")
DvSettingsAcc = New DataView(DsSettingsAcc.Tables("AccSettings"))
myCurrencyManager = CType(SettingsFrm.BindingContext(DvSettingsAcc), CurrencyManager)

'here i am getting error
'Cannot bind to the property or column SelectionValue
'on the DataSource.
'Parameter name: dataMember
SettingsFrm.EasyLvl.DataBindings.Add("Checked", DsSettingsAcc, "SelectionValue")
myCurrencyManager.Position = +1
SettingsFrm.IntermediateLvl.DataBindings.Add("Checked", DvSettingsAcc, "SelectionValue")
myCurrencyManager.Position = +1
SettingsFrm.AdvancedLvl.DataBindings.Add("Checked", DvSettingsAcc, "SelectionValue")

End Sub

Any help will be much appreciated.

Thanks in advanced.
 
I can't talk much on data binding, but some about radio buttons and group boxes. You may already know this, but in case you don't.

When using a GroupBox with radio buttons by default you cannot work directly with each radio button. Instead you have to work directly with the GroupBox because by default the group box is going to try to force only one radio button to be selected at a time. In theory this should apply to data binding as well and you would bind the data to the GroupBox rather than the individual selections.

In a non-binding situation you can set the individual radio buttons to ignore the group box, but you then have to control the behavior of the radio buttons on your own. If I remember right all you have to do is set AutoCheck to false. Then you have to setup your own code on the Click event to toggle the Checked value back-and-forth between True and False. However this is only 50/50 whether this would be possible with data bound to the control because the default behavior for a bound control is to display the data it is bound to.

-I hate Microsoft!
-Forever and always forward.
 
Thank you sorwen effort me.
Without groupbox i still have the same problem...
The field SelectionValue's type in settings table in my database is bit. I don't know if it produces any problem.
Any help will be much appreciated.

Thanks again
 
I have tried this:

BooleanReturned = CBool(DsSettingsAcc.Tables("AccSettings").Rows(myCurrencyManager.Position + 1).Item("SelectionValue"))

SettingsFrm.EasyLvl.DataBindings.Add("Checked", DvSettingsAcc, BooleanReturned)

'BooleanReturn is a declared boolean variable.
But with no effect. Any suggestions?
 
Have you tried putting a break on the code to see what BooleanReturned is showing? Is it showing the correct data?

I would have figured there would be something in the databinding that would do it, but for microsoft a bit and a Boolean are different things. I will never understand, but Microsoft decided a boolean was -1 and 0 and a bit is 1 and 0. That is my side complaint though. When assigning like you did to a Boolean variable it should be converting correctly because Microsoft was at least smart enough to say when converting to a boolean false is always 0 and anything else is true. I would think that would apply to direct binding too.

-I hate Microsoft!
-Forever and always forward.
 
Thank you Sorwen i am getting error there "Object reference not set to an instance of an object."
I just tried :
SettingsFrm.EasyLvl.DataBindings.Add("Checked", DvSettingsAcc(0), "SelectionValue")
SettingsFrm.IntermediateLvl.DataBindings.Add("Checked", DvSettingsAcc(1), "SelectionValue")
SettingsFrm.AdvancedLvl.DataBindings.Add("Checked", DvSettingsAcc(2), "SelectionValue")
It works but I don't think it's a good idea of (0,1,2). I know that I have 3 records, but I think something else I must be placed there.
 
I solved it:

SettingsFrm.EasyLvl.DataBindings.Add("Checked", DvSettingsAcc(myCurrencyManager.Position), "SelectionValue")
myCurrencyManager.Position += 1
SettingsFrm.IntermediateLvl.DataBindings.Add("Checked", DvSettingsAcc(myCurrencyManager.Position), "SelectionValue")
myCurrencyManager.Position += 1
SettingsFrm.AdvancedLvl.DataBindings.Add("Checked", DvSettingsAcc(myCurrencyManager.Position), "SelectionValue")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top