Silverlight 3: ComboBox, Cannot implicitly convert type

4 posts, 0 answers
  1. King Chan
    King Chan avatar
    30 posts
    Member since:
    Feb 2010

    Posted 18 Feb 2010 Link to this post




    using System;  
    using System.Windows.Controls;  
     
    namespace EventsHandling   
    {  
        public partial class Page : UserControl  
        {  
            public Page()  
            {  
                InitializeComponent();  
                  
                Telerik.Windows.Controls.SelectionChangedEventHandler();  
                RadComoBox.SelectionChanged += new EventHandler<SelectionChangedEventArgs>(radComboBox_SelectionChanged);  
                  
            }  
     
            void radComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)  
            {  
                message.Text = String.Format("{0} have been selected.", RadComoBox.Text);  
            }  
     
        }  
    }  
    )  
     
     

    Hi,

    I am trying to let user select the item from combox and print out the combox item text.
    So by doing that, I am subscribe the selection changed event to eventhandler.....

    But it gives me the following error:
    Error 1 Cannot implicitly convert type 'System.EventHandler<System.Windows.Controls.SelectionChangedEventArgs>' to 'Telerik.Windows.Controls.SelectionChangedEventHandler' C:\[Visual Studio 2008 Projects]\RadControlsSilverlightApplication1\RadControlsSilverlightApplication1\MainPage.xaml.cs 16 44 RadControlsSilverlightApplication1

    And the above is my code...

    I tried to follows the example for calendar from RadControls for Silverlight Document to attach the event handler but it gives the same error...

    I am using:
    Visual Studio 2008
    Silverlight 3
    RadControls for Silverlight Q3 2009 SP2
    Windows XP Tablet PC Edition

    Thanks

  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 Feb 2010 Link to this post

    Hello,

    The event args of RadComboBox's SelectionChanged event are of different type, hence the error. You should change your code like this:
    void radComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)

        message.Text = String.Format("{0} have been selected.", RadComoBox.Text);
    }

    By the way, in case your code is not just a sample demonstrating the problem, there is a much easier way to update a TextBlock with the value of the Text property of RadComboBox, entirely in XAML:
    <TextBlock Text="{Binding Text, ElementName=combo}" />
    <telerikInput:RadComboBox x:Name="combo" ... />

    Generally in Silverlight/WPF I would strongly recommend using bindings and ViewModels over handling the control events. The bindings will save you lots of lines of code.

    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. King Chan
    King Chan avatar
    30 posts
    Member since:
    Feb 2010

    Posted 19 Feb 2010 Link to this post

    Thanks, it worked with using:
    XAML:
    <TextBlock Text="{Binding Text, ElementName=combo}" />
    <telerikInput:RadComboBox x:Name="combo" ... />

    But with changing SelectionChangedEventArgs  to Telerik.Windows.Controls.SelectionChangedEventArgs , it only resolved the error, but the "message" text block is not changing at all.
    I want to use the selection changed event to trigger the RadCombox_SelectionChanged method, so I can do different things with the selected item value. (Yes, I want to do more complicate things)

    I wonder if I made any mistake in my code?
    MainPage.xaml.cs
    using System;  
    using System.Windows.Controls;  
     
    namespace EventsHandling   
    {  
        public partial class Page : UserControl  
        {  
            public Page()  
            {  
                InitializeComponent();  
            
            }  
     
            void RadComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)  
            {  
                message.Text = String.Format("{0} have been selected.", RadComboBox.SelectedItem);  
            }  
     
     
        }  
    }  
     

    MainPage.xaml:
    <UserControl xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"  x:Class="EventsHandling.Page" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
      <Grid x:Name="LayoutRoot">  
     
            <StackPanel> 
                <telerikInput:RadComboBox x:Name="RadComboBox" Text="- Select Item -">  
                         <telerikInput:RadComboBoxItem x:Name="RadComboBoxItem" Content="ABC"/>  
                    <telerikInput:RadComboBoxItem x:Name="RadComboBoxItem2" Content="DEF"/>  
                    <telerikInput:RadComboBoxItem x:Name="RadComboBoxItem3" Content="GHI"/>  
                </telerikInput:RadComboBox> 
                <TextBlock x:Name="message"/>  
            </StackPanel> 
            
        </Grid> 
    </UserControl> 
     

    And a side question if you don't mind, I wonder if is possible that I can use this RadControl for Silverlight with JSP or PHP instead of ASP. Net?
    Sorry, I am new to silverlight and Telerik products. :)

    Thanks,
    King
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 Feb 2010 Link to this post

    Hi,

    In your code the event handler is not attached. I guess that the following will resolve the problem:
    <telerikInput:RadComboBox x:Name="RadComboBox" Text="- Select Item -" SelectionChanged="RadComboBox_SelectionChanged">
    <telerikInput:RadComboBoxItem x:Name="RadComboBoxItem" Content="ABC"/>
    <telerikInput:RadComboBoxItem x:Name="RadComboBoxItem2" Content="DEF"/>
    <telerikInput:RadComboBoxItem x:Name="RadComboBoxItem3" Content="GHI"/>
    </telerikInput:RadComboBox>


    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top