Value type 'String' cannot be converted to 'Telerik.Wincontrols.RadItem

6 posts, 0 answers
  1. gdijim
    gdijim avatar
    13 posts
    Member since:
    May 2007

    Posted 06 Jun 2007 Link to this post



    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


  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 06 Jun 2007 Link to this post

    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:

    If Me.RadComboBox1.FindItemExact(Me.RadComboBox1.Text) Is Nothing Then

    I hope this helps.
     

    Greetings,

    Georgi
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. gdijim
    gdijim avatar
    13 posts
    Member since:
    May 2007

    Posted 06 Jun 2007 Link to this post

    Almost done at work for the day - Will try that out when I get home.

    You guys are awsome!  What a response time ;)

    Jim
  5. gdijim
    gdijim avatar
    13 posts
    Member since:
    May 2007

    Posted 07 Jun 2007 Link to this post

    Okay, I've got it to where I can check the Combobox to see if the text already resides there:

    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


  6. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 07 Jun 2007 Link to this post

    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
  7. gdijim
    gdijim avatar
    13 posts
    Member since:
    May 2007

    Posted 07 Jun 2007 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready