ComboBoxEditorSettings

6 posts, 0 answers
  1. Ramón
    Ramón avatar
    10 posts
    Member since:
    Jun 2005

    Posted 25 Feb 2009 Link to this post

    Hi,  how does ComboBoxEditorSettings would work when using custom classes instead of list of strings as ItemsSource.  I have downloaded several projects from other posts, like 114807_silverlightapplication1.zip, where you use list of String and the editor works.  But If I use a  list of a custom class, i stops working.  First, when the cell enters edit mode and shows the combobox, the selectedItem is always null.  Then, if you select an item from the combobox and move to another cell/row, thus ending the edit mode, it displays the custom class's .ToString representation.   

    What are the steps necessary to use the ComboBoxEditorSettings  with customs classes as Itemssource?

    Thanks,

    Ramón.
  2. Jordan
    Admin
    Jordan avatar
    123 posts

    Posted 26 Feb 2009 Link to this post

    Hi Ramon,

    To use custom classes with ComboBoxEditorSettings you should set its DisplayMemberPath and SelectedValuePath. Look at line 17,18.

    1 public class Country 
    2
    3     public int Id { getset; } 
    4     public string Name { getset; } 
    5     public string ContactName { getset; } 
    6
    7  
    8 public partial class Page : UserControl 
    9
    10   public Page() 
    11   { 
    12       InitializeComponent(); 
    13  
    14       RadGridView1.ItemsSource = GetCustomers(XDocument.Load("Customers.xml")); 
    15  
    16       ComboBoxEditorSettings comboBoxEditorSettings = new ComboBoxEditorSettings(); 
    17       comboBoxEditorSettings.DisplayMemberPath = "Name"
    18       comboBoxEditorSettings.SelectedValuePath = "Id"
    19       comboBoxEditorSettings.ItemsSource = GetCountries(); 
    20        
    21       ((GridViewDataColumn)this.RadGridView1.Columns[3]).EditorSettings = comboBoxEditorSettings; 
    22       RadGridView1.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(RadGridView1_SelectionChanged); 
    23   } 
    24  
    25   private static List<Country> GetCountries() 
    26   { 
    27       List<Country> countries = new List<Country>(); 
    28  
    29       countries.Add(new Country { Name = "Germany", Id = 1 }); 
    30       countries.Add(new Country { Name = "Mexico", Id = 2 }); 
    31       countries.Add(new Country { Name = "UK", Id = 3 }); 
    32  
    33       return countries; 
    34   } 
    35


    Regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Ramón
    Ramón avatar
    10 posts
    Member since:
    Jun 2005

    Posted 26 Feb 2009 Link to this post

    Sorry, I should make myself clear.  The comboBox  inside the grid already shows my object's property as defined in DisplayMemberPath.  But, the real problem is that it is not "binded" to the value of the grid's column. I mean, using your example, if you have a grid displaying a  list of 10 Customers, the 4th column contains the Id of the country, when entering edit mode, the combobox should display the Country with the same id as the column.  If you select another Country from the Combobox, then the grid's row dataitem  (Customer) should change its corresponding property value as the SelectedValue of the Combobox.    

    What I do have right now, is that when  my cell enters edit mode, the selectedItem  of the combobox is null (Displays nothing).  If i open the comboboxx, whick correctly shows the items from the list, and make a selection and exit edit mode, the column shows the ToString representation of my  object used in the COmbobox.

  5. Jordan
    Admin
    Jordan avatar
    123 posts

    Posted 27 Feb 2009 Link to this post

    Hello Ramon,

    Sorry for the misunderstanding. 
    In our RadGridView for Silverlight ComboBoxEditorSettings.SelectedValuePath doesn't do anything.
    We are using the standard ComboBox and it hasn't SelectedValuePath and SelectedValue properties. 

    To set the correct value after edit, you should attach to the GridViewCell.EditEndedEvent. In the handler you can set the right value.

    1 public partial class Page : UserControl 
    2
    3   public Page() 
    4   { 
    5     InitializeComponent(); 
    6  
    7     RadGridView1.ItemsSource = GetCustomers(XDocument.Load("Customers.xml")); 
    8  
    9     ComboBoxEditorSettings comboBoxEditorSettings = new ComboBoxEditorSettings(); 
    10     comboBoxEditorSettings.DisplayMemberPath = "Name";  
    11     comboBoxEditorSettings.SelectedValuePath = "Id";  
    12     comboBoxEditorSettings.ItemsSource = GetCountries(); 
    13     ((GridViewDataColumn)this.RadGridView1.Columns[3]).EditorSettings = comboBoxEditorSettings; 
    14     RadGridView1.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(RadGridView1_SelectionChanged); 
    15  
    16     RadGridView1.AddHandler(GridViewCell.EditEndedEvent, new EventHandler<CellRoutedEventArgs>(EditEndedEventHandler)); 
    17   } 
    18  
    19   private void EditEndedEventHandler(object sender, CellRoutedEventArgs e) 
    20   { 
    21     GridViewCell cell = (GridViewCell)e.OriginalSource; 
    22     cell.Value = ((Country)e.NewValue).Name; 
    23   } 
    24


    Best wishes,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Nik
    Nik avatar
    14 posts
    Member since:
    Jan 2007

    Posted 01 Apr 2009 Link to this post

    Hi

    I have wrote following line of code in new() of my page

            Me.rdgView.[AddHandler](GridViewCell.PreviewEditStartEvent, New EventHandler(Of Cells.CellCancelRoutedEventArgs)(AddressOf Me.PreviewEditStart))
            Me.rdgView.[AddHandler](GridViewCell.EditEndedEvent, New EventHandler(Of Cells.CellRoutedEventArgs)(AddressOf EditEndedEventHandler))
            Me.rdgView.[AddHandler](GridViewRow.EditEndedEvent, New EventHandler(Of RecordRoutedEventArgs)(AddressOf Me.OnEditEnded))

    Private Sub OnEditEnded(ByVal sender As Object, ByVal e As RecordRoutedEventArgs)
    'something
    End Sub

      Private Sub EditEndedEventHandler(ByVal sender As System.Object, ByVal e As Cells.CellRoutedEventArgs)
     Dim cel As GridViewCell = TryCast(e.OriginalSource, GridViewCell)

            cel.Value = TryCast(e.NewValue, listitem).Name
        End Sub

        Public Sub PreviewEditStart(ByVal sender As Object, ByVal e As Cells.CellCancelRoutedEventArgs)
    'something
        End Sub

    But I am not able to get either of this event raised. I am not sure what I need to do get this event raised.

    Any help would really appreciated.

    Regards,
    Nikhil





     Dim cel As GridViewCell = TryCast(e.OriginalSource, GridViewCell)

            cel.Value = TryCast(e.NewValue, listitem).Name
        End Sub






  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 03 Apr 2009 Link to this post

    Hello Nik,

    I am not sure of the version you use but these events have been lately ( with the last oficial version) replaced by the RadGridView.RowEditEnded and RadGridViewCellEditEnded.

    I am attaching a small sample which demonstrates row by row editing. It is In C#. Please let me know if you need me to convert it for you into VB.

    Please note that in a few days we are going to have a servicing release ( Q1 SP1) . It will contain some editing issues  fixed as well as a new ComboBox column.



    All the best,
    Pavel Pavlov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top
DevCraft banner