Hi Nat,
To start, you are correct in setting the DataSource after the DispalyMember
and ValueMember. This is more efficient because the control only get bound
once instead of 3 times. You are also correct in that if the datasource
becomes null the DisplayMember will be reset to string.Empty.
The two things I can think of is. The first is redesign so that you the
datasource does not become null. Use a datasource that can be empty without
being null like an ArrayList or DataTable. The second is that, as you said,
set the DisplayMember each time you set the bound datasource object to
something. In this case I would use a method that sets the bound datasource
object where you include setting the DisplayMember value so that it is in
one spot.
Note: I don't believe by setting the DisplayMember after the DataSource will
work for you. You would still run into the same problem of the DispalyMember
being reset.
Take care,
Tom Krueger
My Blog - http://weblogs.asp.net/tom_krueger
Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility
This posting is provided "as is" with no warranties and confers no rights.
> Has anyone else noticed the following problem?
>
[quoted text clipped - 15 lines]
> I was just wondering whether this is a known bug, or whether there is
> a good reason for it..
Nat Wallbank - 28 Feb 2005 15:48 GMT
Hi Tom,
Thanks for your reply. I was actually using a custom collection
(based on CollectionBase), so it was never actually null (I just
tested the DataSource with null to see if I got the same effect).
In the end, when setting the DataSource property I think I just
checked whether the current DataSource was empty, and if so set
DisplayMember again before assigning the new DataSource.
Thanks again,
Nat