ComboBox DataBinding

ComboBox DataBinding

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


Brian Criswell posted on Thursday, July 13, 2006

Searching Google and such has not yielded any ideas, so here goes.

I have a ComboBox that is bound to a BindingSource that has a BusinessListBase<T,C> as its DataSource.  The ValueMember points to a Guid property in T and the DisplayMember points to a String property.  A Guid in a BusinessBase<T> is bound to the SelectedValue.  I would like to allow the user to type in one of the items in the BusinessListBase in the ComboBox, because the list could have hundreds of items that start with the same prefix (so allowing the user to type past the prefix and then hit the up and down arrow keys would be useful).  I thought of binding to not only SelectedValue but also Text, but that binds to the Guid and displays the Guid in the text area instead of the String value.  Any ideas?

RockfordLhotka replied on Thursday, July 13, 2006

I think you need another type of combobox control (though I'd love to be wrong). You may have to create your own to get the behavior you want - that's what I've had to do in the past anyway...

PeterRigbye replied on Friday, July 14, 2006

I'm afraid Rocky's correct, this is one of the biggest pains in my opinion trying to deliver Windows-like functionality in a web browser.

You will need a 3rd-party control (or suite). We've used the webcombo product from Intersoft for the past three years, but there are quite a few others on the market.

I did see an atricle recently on using Atlas/AJAX to achieve similar results without buying a control, but never got to try it out.

Cheers,

Brian Criswell replied on Friday, July 14, 2006

PeterRigbye:

I'm afraid Rocky's correct, this is one of the biggest pains in my opinion trying to deliver Windows-like functionality in a web browser.

You will need a 3rd-party control (or suite). We've used the webcombo product from Intersoft for the past three years, but there are quite a few others on the market.

I did see an atricle recently on using Atlas/AJAX to achieve similar results without buying a control, but never got to try it out.

Cheers,



Sorry that I did not make it clear, but I am doing this in a Windows Forms application.

slipmat replied on Sunday, July 16, 2006

The win forms combobox in .Net 2.0 includes autocomplete functionality.
Set the AutoCompleteMode to Suggest or SuggestAppend
& set the AutoCompleteSource to ListItems. This should give you the behaviour your after.
Bind the Display Member to the String property, Value Member to GUID property and then SelectedValue to the GUID property in the root object.
You don't need to bind the Text property.

Cheers

Brian Criswell replied on Sunday, July 16, 2006

Thanks, that did most of what I wanted.  The only downside is that the user gets no indication if they type in somthing that is not in the list.

ajj3085 replied on Monday, July 17, 2006

Your BO should have a business rule that makes sure the value put into your BO via the combo box is a value in the list.

Also, try setting AutoCompleteMode to SuggestAppend, this will give the user's a 'match as they type' experience.

Brian Criswell replied on Monday, July 17, 2006

ajj3085:
Your BO should have a business rule that makes sure the value put into your BO via the combo box is a value in the list.

Also, try setting AutoCompleteMode to SuggestAppend, this will give the user's a 'match as they type' experience.

No invalid value is entering the business object because the user typed in a string that did not match any item in the list.  If you look at a different object in the UI and then come back to the one that was edited with the invalid value, you will see that it still has its previous value.  What I had been hoping for was a databinding error to pop up on the error provider.  Oh well.

ajj3085 replied on Monday, July 17, 2006

That seems odd.  Are you binding SelectedValue to the BO's property which is entered via the combobox?  I thought that if the user typed something that didn't match, it would attempt to set null as the value.

Brian Criswell replied on Monday, July 17, 2006

ajj3085:
That seems odd.  Are you binding SelectedValue to the BO's property which is entered via the combobox?  I thought that if the user typed something that didn't match, it would attempt to set null as the value.

SelectedValue is bound to the Guid.

mr_lasseter replied on Thursday, February 15, 2007

Were you ever able to figure this out?  I am running into the same scenario and it seems that if the item is not in the list the value does not get pushed back to the business object.  I have tried using the Format and Parse events, but they are not called either.  I would think that this is a pretty common scenario.

 

Thanks,

Mike

PeterRigbye replied on Thursday, February 15, 2007

Mike,

            Had forgotten this – long time ago.

We use a 3rd party control (webcombo from Intersoft) which does this fine. I don’t have any experience with doing Windows apps.

 

Cheers,
Peter Rigbye
Managing Director
PASR Technologies Pte Ltd
Reg. No. 200002233K
16 Mohamed Sultan Road, #03-02
Singapore, 238965
T: +65 6238-3416  M: +65 9635-6482 F: +65 6738-3864
E: peter.rigbye@pasr.com.sg  W: http://www.pasr.com.sg

From: mr_lasseter [mailto:cslanet@lhotka.net]
Sent: Friday, 16 February 2007 3:27 AM
To: Peter Rigbye
Subject: Re: [CSLA .NET] ComboBox DataBinding

 

Were you ever able to figure this out?  I am running into the same scenario and it seems that if the item is not in the list the value does not get pushed back to the business object.  I have tried using the Format and Parse events, but they are not called either.  I would think that this is a pretty common scenario.

 

Thanks,

Mike



Copyright (c) Marimer LLC