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

ComboBoxEditorSettings

5 Answers 207 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ramón
Top achievements
Rank 1
Ramón asked on 25 Feb 2009, 12:21 PM
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.

5 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 26 Feb 2009, 01:57 PM
Hi Ramon,

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

public class Country 
    public int Id { getset; } 
    public string Name { getset; } 
    public string ContactName { getset; } 
 
public partial class Page : UserControl 
  public Page() 
  { 
      InitializeComponent(); 
 
      RadGridView1.ItemsSource = GetCustomers(XDocument.Load("Customers.xml")); 
 
      ComboBoxEditorSettings comboBoxEditorSettings = new ComboBoxEditorSettings(); 
      comboBoxEditorSettings.DisplayMemberPath = "Name"
      comboBoxEditorSettings.SelectedValuePath = "Id"
      comboBoxEditorSettings.ItemsSource = GetCountries(); 
       
      ((GridViewDataColumn)this.RadGridView1.Columns[3]).EditorSettings = comboBoxEditorSettings; 
      RadGridView1.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(RadGridView1_SelectionChanged); 
  } 
 
  private static List<Country> GetCountries() 
  { 
      List<Country> countries = new List<Country>(); 
 
      countries.Add(new Country { Name = "Germany", Id = 1 }); 
      countries.Add(new Country { Name = "Mexico", Id = 2 }); 
      countries.Add(new Country { Name = "UK", Id = 3 }); 
 
      return countries; 
  } 


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.
0
Ramón
Top achievements
Rank 1
answered on 26 Feb 2009, 04:35 PM
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.

0
Jordan
Telerik team
answered on 27 Feb 2009, 02:29 PM
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.

public partial class Page : UserControl 
  public Page() 
  { 
    InitializeComponent(); 
 
    RadGridView1.ItemsSource = GetCustomers(XDocument.Load("Customers.xml")); 
 
    ComboBoxEditorSettings comboBoxEditorSettings = new ComboBoxEditorSettings(); 
    comboBoxEditorSettings.DisplayMemberPath = "Name";  
    comboBoxEditorSettings.SelectedValuePath = "Id";  
    comboBoxEditorSettings.ItemsSource = GetCountries(); 
    ((GridViewDataColumn)this.RadGridView1.Columns[3]).EditorSettings = comboBoxEditorSettings; 
    RadGridView1.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(RadGridView1_SelectionChanged); 
 
    RadGridView1.AddHandler(GridViewCell.EditEndedEvent, new EventHandler<CellRoutedEventArgs>(EditEndedEventHandler)); 
  } 
 
  private void EditEndedEventHandler(object sender, CellRoutedEventArgs e) 
  { 
    GridViewCell cell = (GridViewCell)e.OriginalSource; 
    cell.Value = ((Country)e.NewValue).Name; 
  } 


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.
0
Nik
Top achievements
Rank 1
answered on 02 Apr 2009, 01:01 AM
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






0
Pavel Pavlov
Telerik team
answered on 03 Apr 2009, 03:09 PM
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.
Tags
GridView
Asked by
Ramón
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Ramón
Top achievements
Rank 1
Nik
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or