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

RadDropDownList FindItem method

5 Answers 1182 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Veshala
Top achievements
Rank 1
Veshala asked on 10 Feb 2011, 05:50 PM
Hi,

FindItem(string StartsWith) method of RadComboBox to return a RadComboBoxItem with text starting with a given string.

RadComboBoxItem item = radComboBox1.FindItem(strString);

What is the equivalent method in RadDropDownList to find item starting with a given string.

Any help is appreciated.

Thanks

5 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 10 Feb 2011, 11:08 PM
Hello,

This is one way to get back an item

int itemIndex = this.radDropDownList1.FindString("TheStringToFind");
if (itemIndex > -1)
{MessageBox.Show(this.radDropDownList1.Items[itemIndex].Value.ToString());}
else{MessageBox.Show("not found");}

Hope that helps
Richard
0
Peter
Telerik team
answered on 11 Feb 2011, 05:26 PM
Hello Vanita,

Thank you for the writing.

In RadListControl and RadDropDownList's FindString method searches for an item related to the specified string and returns the index of the found item or -1 if no item is found.

So you should use Ricard's solution to find the item.

Do not hesitate to contact us if you have other questions.

Greetings,
Peter
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
RJ
Top achievements
Rank 1
answered on 06 Dec 2012, 10:00 PM

How about for combo.Items.FindByValue whats the equivalent for RadDropdownList?

coz Im having a problem with raddropdownlist.selectedvalue = to my data  which is not firing up.  but for selectedindex its firing up. So I need the code to get the index which is find by value or the valuemember, not the displaymember

Its just weird for just a simple setting of selected value, only the first 4 radDropdownlist  works and the rest stays at selected index -1
I did change several RadDropdownlist to Wincontrols.Combobox and it works without any problem.
Im using Wincontrols Q2 2012

 Private Sub PopulateBarcodeData()
        Dim DTBarcode As New DataTable
        Dim Row As DataRow
        DTBarcode = GetDataTable("Select * from tblBarcodeData where barcodedataid = " & DataID)
        If Not DTBarcode.Rows.Count = 0 Then

            Row = DTBarcode.Rows(0)

'only 4 items works

            Me.cboItems.SelectedValue = CInt(IsDbaseNull(Row("ItemID"), 0))  
            Me.cboBatchNo.SelectedValue = IsDbaseNull(Row("Item Batch No"), "0")        
            Me.cboMixPlain.SelectedValue = CInt(IsDbaseNull(Row("Mix Plain"), 0))
            Me.cboMixChoco.SelectedValue = CInt(IsDbaseNull(Row("Mix Choco"), 0))

'the rest has problems

            Me.cboMachineNo.SelectedValue = CInt(IsDbaseNull(Row("Machine No"), 0))
            Me.cboFlour.SelectedIndex = cint(IsDbaseNull(Row("FlourID")), 0)

            Me.cboSoyaLecithin.SelectedValue = CInt(IsDbaseNull(Row("SoyaID"), 0))
            Me.cboSugar.SelectedValue = Cint(IsDbaseNull(Row("SugarID"),0))
            Me.cboStickerSupplier.SelectedValue = CInt(IsDbaseNull(Row("Sticker SupplierID"), 0))
            Me.cboSleevesSupplier.SelectedValue = CInt(IsDbaseNull(Row("Sleeves SupplierID"), 0))
            Me.cboShippingPlasticSupplier.SelectedValue = CInt(IsDbaseNull(Row("Shipping Plastic SupplierID"), 0))
            Me.cboPOFSupplier.SelectedValue = CInt(IsDbaseNull(Row("POF SupplierID"), 0))
            Me.cboPolyBagSupplier.SelectedValue = CInt(IsDbaseNull(Row("Polybag SupplierID"), 0))
            Me.cboBubblesSupplier.SelectedValue = CInt(IsDbaseNull(Row("Bubbles SupplierID"), 0))
            Me.cboShippingBoxSupplier.SelectedValue = CInt(IsDbaseNull(Row("Shipping Box SupplierID"), 0))
            Me.cboRetailBoxSupplier.SelectedValue = CInt(IsDbaseNull(Row("Retail Box SupplierID"), 0))
            Me.cboLiner1Supplier.SelectedValue = CInt(IsDbaseNull(Row("Liner1 SupplierID"), 0))
            Me.cboLiner1Supplier.SelectedValue = CInt(IsDbaseNull(Row("Liner2 SupplierID"), 0))
            Me.cboPadsSupplier.SelectedValue = CInt(IsDbaseNull(Row("Pads SupplierID"), 0))
            Me.cboFilledEmp1.SelectedValue = CInt(IsDbaseNull(Row("FilledEmp1ID"), 0))
            Me.cboFilledEmp2.SelectedValue = CInt(IsDbaseNull(Row("FilledEmp2ID"), 0))
            Me.cboFilledEmp3.SelectedValue = CInt(IsDbaseNull(Row("FilledEmp3ID"), 0))
            Me.cboFilledEmp4.SelectedValue = CInt(IsDbaseNull(Row("FilledEmp4ID"), 0))
            Me.cboMixedEmp.SelectedValue = CInt(IsDbaseNull(Row("MixedEmpID"), 0))
            Me.cboSealedEmp.SelectedValue = CInt(IsDbaseNull(Row("SealedEmpID"), 0))

     End If
 End Sub

 

0
RJ
Top achievements
Rank 1
answered on 07 Dec 2012, 02:59 PM
Got the solution for Q2 2012...
Its a RadDropdownList Bug if your going to use it like this:
RadDDL.DataSource = DT
RadDDL.DisplayMember = "Text"
RadDDL.ValueMember = "ID"

Setting RadDDL.SelectedValue = ID value wont work :


But if you populate your RadDropdownList by RadLIstDataItem like this:
Dim ObjListItem As RadListDataItem
RadDDL.Items.Clear()
ObjListItem = New RadListDataItem("Text", 1)
RadDDL.Items.Add(ObjListItem)

Setting RadDDL.SelectedValue = ID value will work :
0
Peter
Telerik team
answered on 07 Dec 2012, 04:09 PM
Hello,

Thank you for contacting Telerik support.

You should set the SelectedValue exactly to the same type as the ValueMember column. For example, if the ValueMember column is of type Short and you set the SelectedValue to 15 which is Integer, RadListDataSource cannot find matches between the types and the SelectedValue fails. 
'not correct
radDropDownList.SelectedValue = 15
 
'correct
radDropDownList.SelectedValue = short(15)

I hope this helps Greetings,
Peter
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
DropDownList
Asked by
Veshala
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Peter
Telerik team
RJ
Top achievements
Rank 1
Share this question
or