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

Populating nested combobox

4 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 15 Jun 2010, 03:44 AM
Hi:

I have two comboboxes in RadGridView columns.  In the first, the user selects a customer.  In the second, the user selects a project for that customer.  So when the SelectionChanged event for the first combobox is fired, I do an async call to the database to get the projects for that customer.  When I get the completed event for that database call, I need to set the ItemsSource for the second RadComboBox so it will list the projects.  The problem is, I can't figure out how to find the second combobox.  I know that gvGrid.CurrentCell contains the customer RadComboBox, but  how do I find the 2nd RadComboBox in the next cell?

This is the XAML that defines the column:

                    <radGridView:GridViewDataColumn Header="Project" DataMemberBinding="{Binding ProjectID, Mode=TwoWay}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding ProjName}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <radInput:RadComboBox x:Name="cboProject" DisplayMemberPath="{Binding ProjName}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
 


Thanks,

Terry

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Jun 2010, 06:37 AM
Hi Terry,

 Similar example can be found on this blog post

Greetings,
Vlad
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
Terry
Top achievements
Rank 1
answered on 15 Jun 2010, 11:12 PM
Hi Vlad:

i haven't been able to get that example to work in my scenario.  I'm experimenting with the loaded event for the combobox and it works, sort of.  Here's the XAML:
                    <radGridView:GridViewDataColumn Header="Project" DataMemberBinding="{Binding ProjectID, Mode=TwoWay}" > 
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding ProjName}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <radInput:RadComboBox x:Name="cboProject" DisplayMemberPath="{Binding ProjName}" Loaded="cboProject_Loaded" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
 
and here's the code:
        private void cboProject_Loaded( object sender, RoutedEventArgs e )  
        {  
            ChargeInfo chg = gvTimeSheet.CurrentItem as ChargeInfo;  
            RadComboBox cbo = sender as RadComboBox;  
            cbo.ItemsSource = projects.Where<Project>( x => x.CustomerID == chg.CustomerID );  
            cbo.Text = chg.ProjName;  
 
            // if current text in list, select it  
            if( cbo.Items.Count() == 0 )  
            {  
                cbo.Text = "";  
            }  
            else 
            {  
                for ( int i = 0; i < cbo.Items.Count(); i++ )  
                {  
                    Project proj = cbo.Items[ i ] as Project;  
                    if ( proj.ProjectID == chg.ProjectID )  
                    {  
                        cbo.SelectedIndex = i;  
                        cbo.Text = chg.ProjName;  
                        break;  
                    }  
                }  
                cbo.UpdateLayout();     // items show as blank  
            }  
        }  
 
 
When I set a breakpoint and look at the data, everything is working perfectly.  The dropdown shows the correct number of items.  The width is appropriate for the choices.  However, the entries in the dropdown and the text field are blank.  It's like they are showing transparent text.  Any idea how I can fix this?

Thanks,

Terry






0
Terry
Top achievements
Rank 1
answered on 15 Jun 2010, 11:24 PM
I solved it.  The DisplayMemberpath is not a binding.  it is just a column name, so when I replaced the {Binding} syntax with 

DisplayMemberPath 

 

 

="ProjName"

 

 

 

 

 

the dropdown text became visible.

There is still one issue, however,  the underlying Projectd from the selected Project item does not get pushed back to the underlying structure.  Do I need some sort of TwoWay flag in the radcombobox definition?
0
Vlad
Telerik team
answered on 16 Jun 2010, 06:11 AM
Hi Terry,

 TwoWay bindings will work properly if your object is INotifyPropertyChanged.

Regards,
Vlad
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
Terry
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Terry
Top achievements
Rank 1
Share this question
or