This question is locked. New answers and comments are not allowed.
Private Sub RadButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton2.Click
'Executes Ping.exe -t With RadComboBox1 as Variable
With Me.RadComboBox1
If Not Me.RadComboBox1.Items.Contains(Me.RadComboBox1.Text) Then
.Items.Add(RadComboBox1.Text)
End If
End With
Process.Start("\pingdev.bat", RadComboBox1.Text)
This code works with the VS combobox - I'm trying to figure out what I'm doing wrong -
I get this error -
Value type 'String' cannot be converted to 'Telerik.Wincontrols.RadItem
Can anyone help?
Thanks!
Jim
5 Answers, 1 is accepted
0
Hello gdijim,
The reason you get this error is because the RadComboBox.Items collection contains objects of type RadComboBoxItem instead strings, so its Contains method expects RadItem object as parameter (RadComboBoxItem is RadItem descendant ). In your case, you could use the FindItemExact method:
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The reason you get this error is because the RadComboBox.Items collection contains objects of type RadComboBoxItem instead strings, so its Contains method expects RadItem object as parameter (RadComboBoxItem is RadItem descendant ). In your case, you could use the FindItemExact method:
If Me.RadComboBox1.FindItemExact(Me.RadComboBox1.Text) Is Nothing Then
I hope this helps.
Greetings,
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
gdijim
Top achievements
Rank 1
answered on 06 Jun 2007, 09:43 AM
Almost done at work for the day - Will try that out when I get home.
You guys are awsome! What a response time ;)
Jim
You guys are awsome! What a response time ;)
Jim
0
gdijim
Top achievements
Rank 1
answered on 07 Jun 2007, 05:28 AM
Okay, I've got it to where I can check the Combobox to see if the text already resides there:
But how do I add strings to the combobox?
Sorry, still trying to get a handle on Object oriented programming.
Thanks!
Jim
If Me.RadComboBox1.FindItemExact(Me.RadComboBox1.Text) Is Nothing Then
But how do I add strings to the combobox?
.Items.Add(radComboBox1.Text)
doesn't work, because it's expecting an object, not a string, as you say. Which option should I use to add a string?Sorry, still trying to get a handle on Object oriented programming.
Thanks!
Jim
0
Hello gdijim,
Again, you're trying to use a method from the Items collection with a string parameter. Items collection is a collection of objects of type RadItem, and in the case of the combobox - objects of type RadComboBoxItem. You should always use the RadComboBoxItem type when you work with Items collection.
To add a new item in the combobox you should first create the item and then add it to Items collection:
Dim item1 as RadComboBoxItem = New RadComboBoxItem(Me.RadComboBox1.Text)
I'll suggest reviewing our combobox examples in the examples that come with installation. Each example comes with its C#/VB code (in the tabs located above the example) and you can see how we do things there.
Let me know if this clears things up.
Best wishes,
Georgi
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Again, you're trying to use a method from the Items collection with a string parameter. Items collection is a collection of objects of type RadItem, and in the case of the combobox - objects of type RadComboBoxItem. You should always use the RadComboBoxItem type when you work with Items collection.
To add a new item in the combobox you should first create the item and then add it to Items collection:
Dim item1 as RadComboBoxItem = New RadComboBoxItem(Me.RadComboBox1.Text)
I'll suggest reviewing our combobox examples in the examples that come with installation. Each example comes with its C#/VB code (in the tabs located above the example) and you can see how we do things there.
Let me know if this clears things up.
Best wishes,
Georgi
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
gdijim
Top achievements
Rank 1
answered on 07 Jun 2007, 08:15 PM
That did it - and you explained a a very important piece of programming I've been missing - A lot of things just clicked.
You guys are really great - thanks for the help,
Jim
You guys are really great - thanks for the help,
Jim