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

[Solved] How do I properly bind this combobox in the Gridview?

0 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fred
Top achievements
Rank 1
Fred asked on 10 Dec 2009, 08:45 PM
I'm having trouble databinding here. This is more of a silverlight question I guess then Telerik, as I had same problem with Telerik Combo's
I have a Telerik GridView that has two columns. I bind rows to the GridView but only have data for the first column. I want the user to select values from comboboxes in the second column.  The Display values show up properly but the values come back as my class name instead of the actual value. Can't figure out now to have the comboboxes give me the actual values, I feel I'm not binding it right. Instead of the value of Import ImportDataFieldName I get "WCFService.ImportSystemFields" actual class name

<telerikGridView:RadGridView  
                x:Name="gvHeaders"  
                ShowGroupPanel="False"  
                Margin="-72,145,-2,54"  
                CanUserReorderColumns="False" 
                CanUserInsertRows="False" 
                CanUserSortColumns="False"  
                HorizontalAlignment="Left" 
                AutoGenerateColumns="False" 
                IsReadOnly="False" 
                Foreground="Black" 
                CanUserSelect="True" Background="{x:Null}" Width="500" 
                > 
                    <telerikGridView:RadGridView.Columns> 
                        <telerikGridView:GridViewDataColumn  
                        Header="Your Import Headers"  
                        UniqueName="ImportHeaders"  
                        IsReadOnly="True" 
                        Background="{x:Null}" 
                        DataMemberBinding="{Binding HeaderField}" /> 
                        <telerikGridView:GridViewDataColumn Header="System Fields" UniqueName="SystemFields"
                            <telerikGridView:GridViewColumn.CellTemplate> 
                                <DataTemplate> 
                                    <ComboBox x:Name="cmbTestCombo"  
                                        SelectedItem="{Binding Path=ImportDataFieldName, Mode=TwoWay}" 
                                        Loaded="SetDataForCombo" 
                                        DisplayMemberPath="DisplayName" 
                                        Height="24" Width="120"
                                    </ComboBox> 
                                </DataTemplate> 
                            </telerikGridView:GridViewColumn.CellTemplate> 
                        </telerikGridView:GridViewDataColumn> 
                    </telerikGridView:RadGridView.Columns> 
                </telerikGridView:RadGridView> 

My Class that binds to the Gridview
Public Class ImportHeaderData 
    Implements INotifyPropertyChanged 
 
    Private _headerfield As String 
    Public Property HeaderField() As String 
        Get 
            Return _headerfield 
        End Get 
        Set(ByVal Value As String
            _headerfield = Value 
            FirePropertyChange("HeaderField"
        End Set 
    End Property 
 
    Private _importDataFieldName As String 
    Public Property ImportDataFieldName() As String 
        Get 
            Return _importDataFieldName 
        End Get 
        Set(ByVal value As String
            _importDataFieldName = value 
            FirePropertyChange("ImportDataFieldName"
        End Set 
    End Property 
 
    Public Shared Function GetData(ByVal SourceString As String()) As List(Of ImportHeaderData) 
        Dim Source As New List(Of ImportHeaderData) 
        Dim oData As ImportHeaderData 
        For Each Item As String In SourceString 
            oData = New ImportHeaderData 
            oData.HeaderField = Item 
            oData.ImportDataFieldName = "UserRequestID" 
            Source.Add(oData) 
        Next 
        oData = Nothing 
        Return Source 
    End Function 
 
    Private Sub FirePropertyChange(ByVal PropertyName As String
        RaiseEvent PropertyChanged(MeNew PropertyChangedEventArgs(PropertyName)) 
    End Sub 
 
    Public Event PropertyChanged(ByVal sender As ObjectByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged 
End Class 

I bind it to grid on new()
Public Sub New() 
        InitializeComponent() 
        gvHeaders.ItemsSource = ImportHeaderData.GetData("rowvalue1,value2,value4".Split(",")) 
    End Sub 

then on Combobox load I bind this class.

Public Shared DestinationAreaSystemFields As ObservableCollection(Of WCFService.ImportSystemFields) 



    Private Sub SetDataForCombo(ByVal sender As System.ObjectByVal e As System.Windows.RoutedEventArgs) 
 
        CType(sender, System.Windows.Controls.ComboBox).ItemsSource = Helper.DestinationAreaSystemFields 
 
    End Sub 


<DataContract()> _ 
Public Class ImportSystemFields 
 
    Private _DataFieldName As String 
    <DataMember()> _ 
    Public Property DataFieldName() As String 
        Get 
            Return _DataFieldName 
        End Get 
        Set(ByVal Value As String
            _DataFieldName = Value 
        End Set 
    End Property 
 
 
    Private _displayName As String 
    <DataMember()> _ 
    Public Property DisplayName() As String 
        Get 
            Return _displayName 
        End Get 
        Set(ByVal Value As String
            _displayName = Value 
        End Set 
    End Property 
 
End Class 


Tags
GridView
Asked by
Fred
Top achievements
Rank 1
Share this question
or