Property bound to ComboBox ApplyReadRules issue for WinForms

Property bound to ComboBox ApplyReadRules issue for WinForms

Old forum URL: forums.lhotka.net/forums/t/1018.aspx


Tommybouy posted on Friday, August 25, 2006

I have a property that is bound to a ComboBox via the databindings text value. The combo is also populated with a ReadOnlyList that is bound as the datasource. All works well except that on existing records the saved value would not display correctly. It always showed the first value in the list. I added code during the form load to populate the text value with the saved property value and this seemed to fix the issue. Now that I am trying to implement read/write rules I am having a problem where the text value is not being blanked out if the users role does not have read rights.

Am I doing this incorrectly or maybe there is a better way?

Thanks

Tommybouy Geeked [8-|]

Tray replied on Friday, August 25, 2006

Tommybouy,

It initially appears that you may not be using the correct property in the combo box. It looks like you are trying to change the text property of the combo box whilst it is bound.

Attaching a static list to a combo box
ComboBox1.DataSource = mStaticList
ComboBox1.DisplayMember = "PropertyToDisplay"
ComboBox1.ValueMember = "PropertyToSelect"

This will bind a static list to the combo box and display it.
The data source property is set to an IList object (your list object).
The display member property is the name of the list property which you want displayed in the combo box list.
The value member property is the name of the list property which should be stored in your object when an item is selected.

Binding a combo box to your object
ComboBox1.DataBindings.Add("SelectedValue", mObjectToBindTo, "ObjectProperty")

This will bind your object property to the selected value of the combo box.
The first argument in the Add method is the property of the combo box to bind to - in this case it is the SelectedValue property. This is because the value that you are storing is (probably) different to what is being displayed.
The second argument in the Add method is your object.
The third argument in the Add method is the property in your object that you want to store the selected value.

Now you have a combo box which knows where to look for the list to display, what to display and what value to select, as well as where to put that value.

Hope this helps

Tray

Copyright (c) Marimer LLC