Getting the combo's display text from the corresponding edit value


Author
Message
Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
I have an inherited DevEx combo box, and I'm trying to do the following:

-If given a Value member (e.g. customer primary key) find the corresponding display text (e.g. customer name) as it shows in the combo box. 

So, say I have the following in a combo box where the first is the display text and second is the value member.

Andria Jensen - 5
Trent Taylor - 10
Ben Chase - 3

I should be able to find the text "Andria Jensen" from the combo box if I have the value 5.  I know you can do this with the Text property if you are trying to get the currently selected text.  However, what if I'm trying to get something that was previously selected?  Say comparing an original to a current value. 

I found this, but it doesn't seem to work correctly in all cases:
ComboBoxCtl.Properties.GetDisplayText(EditValueToFind)

How would you guys go about accomplishing this?

Peter Denton
Peter Denton
StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)StrataFrame Novice (109 reputation)
Group: Forum Members
Posts: 77, Visits: 787
G'day

I'd recommend that instead of using the devexpress ComboBoxEdit, you should use the devexpress LookupEdit. The LookupEdit can be populated from a BO via a BBS and so you would be doing all your searching in a familiar strataframe BO.

We don't use the ComboBoxEdit at all, we've found the LookupEdit far more flexible.

Peter 

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
If you don't want to change your combo over to a LookupEdit control, the I would recommend looking at the DataSource of the combo instead of trying to look at the text property.  When you populate the combo via a PopulationDataSource mechanism, we will create a data table that gets attached to the DataSource of the combo.  There will be two columns within the data table (I am not positive, but it will be something like Display and Value for the names, but you can test this on a debug or something).  At any rate, I would use the ADO.NET route as it will always be faster in this case.  For example:

If DirectCast(MyCombo.DataSource, DataTable).Select("Display = '" & MySearchValue & "'").Length > 0 Then
    '-- You have a hit, you can get the value from the results in the above query, etc.
End If

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Oh...by the way, I noticed that you had something wrong in your sample above, it should have been like this:

Trent Taylor = 1

BigGrin

Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Well, I think I solved it with a function of my own.  How's this?

Public Shared Function GetDisplayText(ByVal combo As MicroFour.StrataFrame.UI.Windows.Forms.DevEx.ComboBoxEdit, ByVal EditValue As Object)

  For i As Integer = 0 To combo.Properties.Items.Count - 1
     If combo.Items(i).Value = EditValue Then Return combo.Items(i).Display
 
Next

  Return EditValue
End Function

 

And yes, Trent...On a scale of 1-10, 10 being the highest...you're right, you are 1.  Cool


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Looks good Smile  There is always more than one way to skin a cat...so to speak...I hope I didn't offend any cat lovers out there BigGrin
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I love cats . . . I just can't eat a whole one by myself.

Smooooth

Andria Jensen
Andria Jensen
StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)StrataFrame User (406 reputation)
Group: Forum Members
Posts: 336, Visits: 497
I think my dog could eat a whole one...
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
LOL...

I love cats . . . I just can't eat a whole one by myself.

Depends on the size of the cat Tongue

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search