This is a migrated thread and some comments may be shown as answers.

Combo Mysteriously Selecting and Reverting by Itself

9 Answers 115 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Simon Kingaby
Top achievements
Rank 2
Simon Kingaby asked on 25 Jun 2008, 08:47 PM
I have several RadComboBoxes in a GridEditTemplate.  They are all very similar and all but one are working perfectly.  The last one on the page mysteriously resets itself after a short delay.  There are three list items in the combo, the first has a Values of "0", then "Key170-1" then "Key360-7"
the default should be setting to "0", but instead it is picking "Key170-1", but when I pick "Key360-7", as soon as the combo loses focus, it magically reverts back to "Key170-1".
I cannot find any code, client side or server side, Javascript, ASPX, nor code-behind that explains this behaviour, and it is only for this one combo out of 10 on the form. 
Please help!
Thanks,
Simon

9 Answers, 1 is accepted

Sort by
0
Thomas Barbour
Top achievements
Rank 1
answered on 25 Jun 2008, 10:04 PM
I have the same issue, using 2008.1.619.

I have several Rad ComboBoxes on the page, and one of them does not work.

That one has the same behavior as yours, it has 3 items (not template items, just standard ones) The 1st one just says "Select..." and has a value of -1, the other two have some random binary strings and the values are 0.

Whenever I Select the 3rd item, and then change the focus to the page or another control, it automatically selects the 2nd item.

The only thing different about the control that is different than the others is that it is dynamically added to the page using LoadControl(...); and Controls.Add(...); and it is a user control embedded within another user control.

I tried putting breakpoints in all different parts of the page load and the setting of the combo box values, and the selected index changed event and none of these methods are triggered when the automatic selection occurs, it may be something on the client side.

Please advise.

Thanx, T.J.
0
Simon Kingaby
Top achievements
Rank 2
answered on 25 Jun 2008, 10:44 PM
Unfortunately for Thomas, I was able to figure this out in my situation.
All of my combos use a Long key and a String description, except the last one, which uses a String key.  Dohn!  All of my code in my BaseComboBox was using Long keys and it was failing out on that last one where the Key was a string.  Now, why I couldn't trap this error and why I couldn't step through it is still a mystery to me.  The mysterious behaviour is troublesome, though I found and fixed the cause in my situation.
0
Thomas Barbour
Top achievements
Rank 1
answered on 25 Jun 2008, 11:42 PM
Simon, thanks for the heads up.

Could you be a little more specific about what you mean by "Key" and "Description"

Are you referring to the DataTextField and the DataValueField properties of the RadComboBox and what the data types are in the DataSource items?

I just want to make sure I understand in case I'm not doing something similar.

Thanx much,
T.J.
0
Simon Kingaby
Top achievements
Rank 2
answered on 26 Jun 2008, 01:33 PM

Yes.  We use SubSonic for our Data Access Layer.  I created a BaseComboBox that inherits from the RadComboBox and adds the functionality to Bind itself to a Subsonic.Select query result.  The function that creates the list is shwon below.  Yesterday, this was converting the rdr.GetValue(0) into a Long and passing it in as a long to lst.Add.  That was the code I changed, and now my combos are behaving predictably.  Here is the code:

        Private Shared Function ParseQueryIntoListItems(ByVal qry As [Select]) As IList(Of RadComboBoxItem)
            'run the query, get back a Reader
            Dim rdr = qry.ExecuteReader()
            Dim lst As New List(Of RadComboBoxItem)()
            'loop through the reader, creating ListItems
            While rdr.Read()
                Dim id = rdr.GetValue(0)
                Dim text = rdr.GetString(1)
                lst.Add(New RadComboBoxItem(text, id))
            End While
            'Add a blank row with a key of "0"
            lst.Add(New RadComboBoxItem("", "0"))
            Return lst
        End Function
       
This function result is then passed back to this function, which clears the Items collection and reloads it from the IList(Of RadComboBoxItem):

        Private Sub MainLoadItems(ByVal id As String, ByVal parentIdfk As String, ByVal filterText As String, ByVal whereClauses As IList(Of Constraint))
            Me.Items.Clear()
            Me.Items.AddRange(GetListItems(id, parentIdfk, filterText, whereClauses))
        End Sub
       
Hope that helps,
Simon

0
Eric Schoenholzer
Top achievements
Rank 2
answered on 18 Aug 2008, 09:59 AM

Thomas,

Had you any success?

I have the same behavior like you:

Three RadComboBoxes created by code and they are using the event ItemsRequested.

One rcb jumps back to first item, when I click on the page.

Thanks

Eric

0
Thomas Barbour
Top achievements
Rank 1
answered on 18 Aug 2008, 05:24 PM
Hi Eric and all,

Sorry I didn't post this sooner...

Turns out the reason this was happening to me was because I had multiple items in my combo box with the same Value.

Actually, in my case all of the items had the same value, becuase I was not actually using the value and just the text in the combo box, I had set the value of all the items to be -1.

Turns out, when a combo box has more than one item with the same value, after selection of one of those items, it will select the 1st one with that value.

I fixed mine by making sure that all my combo box items had distinct values.

Hope this helps, T.J.
0
Eric Schoenholzer
Top achievements
Rank 2
answered on 19 Aug 2008, 09:20 PM
Hi Thomas,

Thanks for the hint, my values were the same too.
 
Eric
0
Armand
Top achievements
Rank 1
answered on 29 Jan 2009, 09:11 PM
Thanks for the advice.
This behaviour is still same  in   Version=2008.3.1125.35.

I had the following dataset

recordid     week
1                week1
1                week2
1                week3

In my datavalue settings of combo I had recordid and in my datatext week.
Combo will revert to week1 no matter what week is selected.
As in other posts I want to confirm solution is that each record must be unique.
I was only using week cmbweek.selecteditem.text so I change my value settings to week as well.

0
Veselin Vasilev
Telerik team
answered on 30 Jan 2009, 08:45 AM
Hi Armand,

Yes, the values of the combo items should be different.

All the best,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Simon Kingaby
Top achievements
Rank 2
Answers by
Thomas Barbour
Top achievements
Rank 1
Simon Kingaby
Top achievements
Rank 2
Eric Schoenholzer
Top achievements
Rank 2
Armand
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or