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

Combobox in CellEditTemplate

3 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deven
Top achievements
Rank 1
Deven asked on 30 Jun 2010, 09:29 AM
Hi,
Following code falls over everytime a selected item is changed in the combobox. The error is "Value does not fall with in expected range"

<telerikGrid:GridViewDataColumn   
    Header="Test Type" DataMemberBinding="{Binding TestType}"> 
    </telerikGrid:GridViewDataColumn.CellTemplate> 
    <telerikGrid:GridViewDataColumn.CellEditTemplate> 
        <DataTemplate> 
            <telerikInput:RadComboBox                     
                HorizontalAlignment="Stretch" Margin="2"   
                Style="{StaticResource TelerikComboBoxStyle}" 
                IsEditable="True"   
                telerik:TextSearch.TextPath="Desc" 
                ItemsSource="{Binding TestTypeCollection}"   
                SelectedItem="{Binding TestType, Mode=TwoWay}" /> 
        </DataTemplate> 
    </telerikGrid:GridViewDataColumn.CellEditTemplate>   
</telerikGrid:GridViewDataColumn> 
 

I found a work around to this. I replaced DataMemberBinding with a cell template and now it is working properly. However, I lost the auto sort and filter option.
<telerikGrid:GridViewDataColumn   
    Header="Test Type" > 
    <telerikGrid:GridViewDataColumn.CellTemplate> 
        <DataTemplate> 
            <Grid> 
                <TextBlock Text="{Binding TestType}" /> 
            </Grid> 
        </DataTemplate> 
    </telerikGrid:GridViewDataColumn.CellTemplate> 
    <telerikGrid:GridViewDataColumn.CellEditTemplate> 
        <DataTemplate> 
            <telerikInput:RadComboBox                     
                HorizontalAlignment="Stretch" Margin="2"   
                Style="{StaticResource TelerikComboBoxStyle}" 
                IsEditable="True"   
                telerik:TextSearch.TextPath="Desc" 
                ItemsSource="{Binding TestTypeCollection}"   
                SelectedItem="{Binding TestType, Mode=TwoWay}" /> 
        </DataTemplate> 
    </telerikGrid:GridViewDataColumn.CellEditTemplate>   
</telerikGrid:GridViewDataColumn> 
 

I would like to understand why it was not working in the first case.

Thanks
Deven


3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 30 Jun 2010, 09:38 AM
Hi Deven,
Typically such problem occurs when there is something wrong with the item template of the combo box , or a failing binding relevant to the combo . To be able to give more specific answer I will need to see the implementation of your objects( used as ItemsSource for the combo  and the Gridview) . The full XAML  of the TelerikComboBoxStyle would be also helpful in isolating the problem.

Best wishes,
Pavel Pavlov
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
0
Deven
Top achievements
Rank 1
answered on 30 Jun 2010, 09:59 AM
Grid is bound to a collection of ViewModel. The combobox is bound to a collection of TestType object with in each ViewModel. ViewModel also has a property of type TestType which binds to SelectedItem of the combobox.

TestType has two key fields, IntCode and Desc, both of them are strings. Also the TestType overrides ToString to return Desc. Equals is overridden to compare IntCode.
public class MyViewModel  
{  
  public ObservableCollection<TestType> TestTypeCollection {getset;}  
  public TestType SelectedTestType {getset;}  
}  
 
public class TestType  
{  
  public string IntCode {getset;}  
  public string Desc {getset;}  
    
  public override bool Equals(object obj)  
  {  
    if (obj is TestType)  
      return this.IntCode == ((TestType)obj).IntCode;  
    return false;  
  }  
 
  public override string ToString()  
  {  
    return this.Desc;  
  }  

 

Hope this helps.

 

Thanks

Deven

0
Maya
Telerik team
answered on 05 Jul 2010, 07:29 AM
Hello Deven,

I have created a sample project using your code-snippets and still no error has occurred. Most probably, as my colleague said, the reason for the exception you are seeing is a result of the custom TelerikComboBoxStyle.
I am sending you the application I have developed. Please, feel free to change it so that it meets your requirements.
Furthermore, just as an advice, in this case you may use the GridViewComboBoxColumn

Regards,
Maya
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
Tags
GridView
Asked by
Deven
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Deven
Top achievements
Rank 1
Maya
Telerik team
Share this question
or