PC Review


Reply
Thread Tools Rate Thread

ComboBox refresh display item

 
 
Nick Hoggard
Guest
Posts: n/a
 
      2nd Sep 2004
Hi All,

Really silly question, but how do I get a combo box to refresh the display
field if I update the object that it is based on.

For example, I am populating my combobox by adding instances of a custom
object. That custom object has a ToString property that the combobox uses
as the display field. If I change a property on the custom object then the
ToString value also changes, but the combobox doesn't get refreshed.

Is there something I can call to make the combobox refresh the display
fields, or do I have to remove then add the item again?

Cheers

Nick Hoggard


 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      2nd Sep 2004
If combobox is not bound (.DataSource == null ), then your best bet is:
combobox1.Items.[i] = combobox1.Items.[i];

It will force the refresh of the item. It will also reset the selected
index, so you may want to preserve that.

If the combobox is bound to say, ArrayList, it is somewhat more complicated.
Basically, you wil either have to get the CurrencyManager via Reflection and
call Refresh() on it, or implement your own collection that implements
IBindingList and forces bound control to reset on every change. Let me
know, if you need a sample

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Nick Hoggard" <nickh@N0_SPAMxenacom.com> wrote in message
news:%(E-Mail Removed)...
> Hi All,
>
> Really silly question, but how do I get a combo box to refresh the display
> field if I update the object that it is based on.
>
> For example, I am populating my combobox by adding instances of a custom
> object. That custom object has a ToString property that the combobox uses
> as the display field. If I change a property on the custom object then
> the
> ToString value also changes, but the combobox doesn't get refreshed.
>
> Is there something I can call to make the combobox refresh the display
> fields, or do I have to remove then add the item again?
>
> Cheers
>
> Nick Hoggard
>
>



 
Reply With Quote
 
Nick Hoggard
Guest
Posts: n/a
 
      2nd Sep 2004
Thanks Alex,

> If combobox is not bound (.DataSource == null ), then your best bet is:
> combobox1.Items.[i] = combobox1.Items.[i];


Cool, hadn't thought of that approach. Easier than removing then adding
again at same index.

> It will force the refresh of the item. It will also reset the selected
> index, so you may want to preserve that.
>
> If the combobox is bound to say, ArrayList, it is somewhat more

complicated.
> Basically, you wil either have to get the CurrencyManager via Reflection

and
> call Refresh() on it, or implement your own collection that implements
> IBindingList and forces bound control to reset on every change. Let me
> know, if you need a sample


I was binding to an arraylist, but have found it's easier just to loop the
array list and add the item to the combo. I may need to try the Reflection
approach though if I find the ArrayList is needed elsewhere in the app.

Thanks again.

Nick

> > Hi All,
> >
> > Really silly question, but how do I get a combo box to refresh the

display
> > field if I update the object that it is based on.
> >
> > For example, I am populating my combobox by adding instances of a custom
> > object. That custom object has a ToString property that the combobox

uses
> > as the display field. If I change a property on the custom object then
> > the
> > ToString value also changes, but the combobox doesn't get refreshed.
> >
> > Is there something I can call to make the combobox refresh the display
> > fields, or do I have to remove then add the item again?
> >
> > Cheers
> >
> > Nick Hoggard
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
combobox display item when not in list Nick X Microsoft Access Forms 1 3rd Nov 2009 09:18 PM
Combobox not display selected item Mark Boettcher Microsoft C# .NET 3 21st Dec 2007 07:43 PM
Re: How to display the first Item in a combobox as the default item Nigel Microsoft Excel Programming 2 8th Dec 2006 10:21 PM
Re: How to display the first Item in a combobox as the default item Jim Cone Microsoft Excel Programming 0 8th Dec 2006 06:42 PM
display the first item in a combobox Claudia Fong Microsoft C# .NET 1 17th May 2005 05:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:48 AM.