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

Combobox Column

16 Answers 236 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott Rakestraw
Top achievements
Rank 1
Scott Rakestraw asked on 02 Oct 2009, 04:26 PM
My grid is built by metadata which is passed in so all of my work has to be done in code.  I have some fields that are simple lists which work fine with the combobox column.  I also have some which require me to display more than one column which I know the combobox supports.  How would I go about implementing a multi-column combobox in the grid?

16 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 07 Oct 2009, 11:56 AM
Hi Scott ,

Unfortunately the GridViewComboBoxColumn is intended to serve more general scenarios.
For your specific case I would recommend to use the  CellTemplate property  of the  GridViewDataColumn. This way you can place a combo in the cell and style it to achieve the desired multicolumn appearance .

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott Rakestraw
Top achievements
Rank 1
answered on 12 Oct 2009, 06:46 PM
Using XamlReader.Load I am able to create my templates on the fly based on my metadata.  What am I doing is calling a webservice to return the data that will be used to populate this combobox.  On the completed event of getting the data how do I then set the itemsource of the combobox?  I can get a reference to my column and then column.CellEditTemplate.LoadContent will give me a reference to the combobox but setting the itemssource of that does nothing for me.
0
Pavel Pavlov
Telerik team
answered on 13 Oct 2009, 08:55 AM
Hello Scott ,

Can you please paste me a piece of your code and I will try to prepare a working sample . What I need is the logic in the completed event where you have the data to populate the row and the comboBox as well as the definitions of the relevant datatypes.

I am sure we can think of some decent solution here.

Kind regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott Rakestraw
Top achievements
Rank 1
answered on 13 Oct 2009, 01:01 PM
Here is what I am currently doing in my completed event which of course is not working.

        Dim ms As New System.IO.MemoryStream(e.Result) 
        Dim listDS As New C1.Silverlight.Data.DataSet 
        listDS.ReadXml(ms) 
 
        Dim column As GridViewDataColumn = CType(editGrid.Columns(e.UserState.ToString), GridViewDataColumn) 
        Dim combo As RadComboBox = CType(column.CellEditTemplate.LoadContent, RadComboBox) 
        combo.ItemsSource = listDS.Tables(0).DefaultView 
 

If I have a regular combobox column and then bind this dataset to the column's itemsource everything works fine.  I know the loadcontent is not getting me the correct reference to the combobox and that seems to be all that am I missing to get this to work.
0
Pavel Pavlov
Telerik team
answered on 15 Oct 2009, 12:37 PM
Hello Scott ,

I believe the following approach may suit to your scenario:

1. Override the default CellEditTemplate of the ComboBoxColumn
2. Place a user control inside with a combobox styled for multi column appearance.
3.In the code-behind of the user control set the properties of the combo to the relevant properties of the column
4. Place any additional logic to control the combo in the code-behind of the user control

I have demonstrated this with a small project . Please check the attached file.

All the best,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott Rakestraw
Top achievements
Rank 1
answered on 15 Oct 2009, 08:55 PM
I modified this to more closely resemble how I need this to work and it is throwing an error now.  The only real difference is that I'm trying to create the editTemplate in code.  When I try to edit the column I get the dreaded AG_E_PARSER_BAD_TYPE error.  I need to create this in the code since my multicolumncombo class has some public properties that I am filling in with the XAML that I create.

        <telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" > 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" /> 
                <telerik:GridViewComboBoxColumn Width="205" DataMemberBinding="{Binding CountryID, Mode=TwoWay}" DisplayMemberPath="Name" SelectedValueMemberPath="ID" /> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
 

        Public Sub New() 
 
            InitializeComponent() 
 
            Dim persons As New List(Of Person)() 
            persons.Add(New Person(1, "Carlos")) 
            persons.Add(New Person(2, "Hans")) 
            persons.Add(New Person(3, "Pierre")) 
 
            Me.RadGridView1.ItemsSource = persons 
 
            Dim editXAML As String = "<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:local=""clr-namespace:multiColumnCombo_SL""><local:MultiColumnCombo Width=""200"" Height=""Auto"" /></DataTemplate>" 
            Dim editTemplate As New DataTemplate 
            editTemplate = CType(System.Windows.Markup.XamlReader.Load(editXAML.ToString), DataTemplate) 
            RadGridView1.Columns(1).CellEditTemplate = editTemplate 
 
            DirectCast(Me.RadGridView1.Columns(1), GridViewComboBoxColumn).ItemsSource = GetCountries() 
        End Sub 
 

0
Scott Rakestraw
Top achievements
Rank 1
answered on 16 Oct 2009, 06:22 PM
I solved this problem.  In the xmlns:local I added in assembly=multiColumnCombo_SL and it is now working.  Thank you for all your help as this has solved a major issue for me.
0
Scott Rakestraw
Top achievements
Rank 1
answered on 22 Oct 2009, 02:18 PM
I have added a cell template to go along with my edit template so it will be formatted to look like the combobox item template.  I can read the value from the cell and build the textblocks setting their text property to the actually text but that does not update.  How do I bind the control to the selected item in the edit template's combobox.  If I change rows this will fire back through the loaded event and work fine.  How can I either bind this to the selected item or force the load event?  I know I can do it by calling grid rebind on celledit ended but that seems like overkill.

<UserControl x:Class="Silverlight.UQube.multiColumnComboView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    Width="Auto" Height="Auto"
    <Grid x:Name="LayoutRoot"
        <ContentPresenter x:Name="cpTemplate"
             
        </ContentPresenter> 
    </Grid> 
</UserControl> 
    Private _ListID As Integer 
 
    Public Property ListID() As Integer 
        Get 
            Return _ListID 
        End Get 
        Set(ByVal Value As Integer
            _ListID = Value 
        End Set 
    End Property 
 
    Public Sub New() 
        InitializeComponent() 
    End Sub 
 
    Private Sub multiColumnComboView_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
 
        Dim parentColumn As GridViewComboBoxColumn = TryCast(Me.ParentOfType(Of GridViewCell)().Column, GridViewComboBoxColumn) 
 
        Dim list As DataFrameworkReference.DataFrameworkDynamicList = (From dl In DynamicLists _ 
                                                                       Where dl._ListID = ListID _ 
                                                                       Select dl).First 
 
        Dim sp As New StackPanel 
        sp.Orientation = Orientation.Horizontal 
 
        Dim value As Object = Me.ParentOfType(Of GridViewCell)().Value 
        Dim row As DataRow = Nothing 
 
        If Not value Is Nothing Then 
            row = CType(parentColumn.ItemsSource, DataView).Table.Select(String.Format("{0} = '{1}'", list._ValueColumn, value.ToString))(0) 
        End If 
 
        For Each c As DataFrameworkReference.DynamicListColumn In list._Columns 
 
            Dim tb As New TextBlock 
            If Not row Is Nothing Then tb.Text = row.Item(c._Column).ToString 
            sp.Children.Add(tb) 
 
        Next 
 
        cpTemplate.Content = sp 
 
    End Sub 

0
Pavel Pavlov
Telerik team
answered on 26 Oct 2009, 12:25 PM
Hi Scott ,

In such cases I always recommend to implement the INotifyPropertyChanged interface to your business object. This way the RadGridView will listen for the property changed event and will automatically update the screen content as soon as the underlying value has changed.  This will avoid the need of calling the Rebind() method.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott Rakestraw
Top achievements
Rank 1
answered on 26 Oct 2009, 05:49 PM
My underlying business object is actually the component one dataset.  Without being able to make changes to this is there any way outside of the rebind method?  Anyway to just tell a cell to refresh itself?
0
Pavel Pavlov
Telerik team
answered on 29 Oct 2009, 01:56 PM
Hi Scott ,

I believe the following approach may give a result here :

1. Subscribe to the selection changed event of your ComboBox
2. In the handler of this event you  may get a reference to the containing Cell

        *you can use the extension method sender.ParentOfType<GridViewHeaderCell>();
        * you need to cast the sender to FrameworkElement
        * you will need to add the Telerik.Windows.Controls namespace to have this method available

3. Having the cell you now have access to its DataContext which is in fact your business object. Here you set the relevant property of your business object.  This should update the display content .

I have tested it here with a mock business object which does not implement INotifyPropertyChanged and it seems to work.

In case this does not solve the problem you can open a support ticket and send me  your project. I will gladly apply the fixes needed.

Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott Rakestraw
Top achievements
Rank 1
answered on 30 Oct 2009, 08:04 PM
I have the following, but the problem is that the display still does not get updated.

        Dim parentColumn As GridViewComboBoxColumn = TryCast(Me.ParentOfType(Of GridViewCell)().Column, GridViewComboBoxColumn) 
        CType(CType(sender, FrameworkElement).ParentOfType(Of GridViewCell)().DataContext, DataRowView).SetData(parentColumn.UniqueName, multiCombo.SelectedValue) 
 

Since I also have a view and edit template is there some event I need to hook up my view template with so that it can rebuild itself outside of just the Loaded event?
0
Scott Rakestraw
Top achievements
Rank 1
answered on 30 Oct 2009, 08:49 PM
I was able to hook up my view template to the handle the property changed event of the datarow.  I then check in there if it is the column that this view is associated with and then I rebuild the cell.

    Private Sub multiColumnComboView_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
        Dim rv As DataRowView = CType(Me.ParentOfType(Of GridViewCell)().DataContext, DataRowView) 
        AddHandler rv.PropertyChanged, AddressOf PropertyChanged 
        Load() 
    End Sub 
 
    Private Sub PropertyChanged(ByVal sender As ObjectByVal e As System.ComponentModel.PropertyChangedEventArgs) 
        If e.PropertyName = TryCast(Me.ParentOfType(Of GridViewCell)().Column, GridViewComboBoxColumn).UniqueName Then 
            Load() 
        End If 
    End Sub 

0
Scott Rakestraw
Top achievements
Rank 1
answered on 04 Nov 2009, 05:57 PM
I have upgraded to the Q3 release but now column is not using my custom CellEditTemplate.  It applies the custom CellTemplate fine, but completely ignores the edit template and instead just shows the default grid view combobox edit template.
0
Nedyalko Nikolov
Telerik team
answered on 05 Nov 2009, 03:13 PM
Hi Scott Rakestraw,

It seems that you've discovered an issue with GridViewComboBoxColumn and CellEditTemplate property. It is already fixed and will be public via latest internal build program (next Friday - 6-th Nov).

P.S. I've updated your Telerik points accordingly.

All the best,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
David Schulz
Top achievements
Rank 1
answered on 18 Nov 2009, 07:05 PM

Tags
GridView
Asked by
Scott Rakestraw
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Scott Rakestraw
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
David Schulz
Top achievements
Rank 1
Share this question
or