PDA

View Full Version : C# - ComboBox display updating with bound data?



flashbabe
November 30th, 2007, 12:51 AM
This has been bothering me for a while.

I have a comboBox on my form. i have set the datasource to a list I am managing.

How do I get changes to the data in the list to propigate to the Display members shown by the list?

kirupa
November 30th, 2007, 03:01 AM
Is this a WPF application?

flashbabe
November 30th, 2007, 11:47 AM
I had to look up the meaning of WPF :)

No - I'm using VS 2005 .NET. It is a standard Windows Application Form in C#.


The combo box selected index value change causes 2 panes to change. The one pane allows the user to Update information of the Item in the selected index. The other pane displays all database elements FKeying to that item.

So sometimes the user may update the portion of the information that is set as DisplayValue in the combobox. The object itself is updated, but the combobox text remains as the old value.

I'm essentially looking for a best practice in doing this. Whenever updating a member of the combobox should I rebind the datasource? I tried using the Refresh() and Update() methods but they do not update the display value.

Charleh
November 30th, 2007, 12:04 PM
Well I'm not sure about datalists but assuming you have edited the object in memory the binding should reflect the edits. If not I usually just write a Requery method which queries the data source again and rebinds the offending control

You might want to have a look at CSLA - it's a library for maniuplation of business objects supporting parent/child collection heirarchies, error providing, multiple undo levels etc etc - it certainly speeds up creating a business app around here. We usually combine it with CSLAGen which is a template generator based on CodeSmith which generates CSLA objects for you from a database schema - all you need to do is write the sprocs which get/update/delete the data and then it does the rest (you might tweak it a little here and there).

It's got a bit of a learning curve but once you know what you are doing it's invaluable! That would solve your refresh issues :)