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

Untyped datasets and GridViewComboBoxColumn

2 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nic Roche
Top achievements
Rank 1
Nic Roche asked on 30 Oct 2009, 12:49 AM
Hi,

I am having a few issues with consuming datasets with the wpf grid. I have viewed the demos etc but cannot resolve this one.

The problem is the GridViewComboBoxColumn does not display the Display member on load, and when an item is selected in the employee column, and I navigate away, the value selected is not persisted in the grid row.

I have created a small example to show the problem. The codebehind is VB, as that is the language used for this cutover.

<Window x:Class="Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    Title="Window1" WindowState="Maximized">  
    <Grid> 
        <telerik:RadGridView   
                        AutoGenerateColumns="False" 
                        HorizontalAlignment="Right"   
                        IsFilteringAllowed="False" 
                        CanUserFreezeColumns="False"   
                        CanUserReorderColumns="False"   
                        IsEnabled="True" 
                        ColumnsWidthMode="Auto" 
                        CanUserSortColumns="False"                  
                        ShowGroupPanel="False" 
                        ItemsSource="{Binding Tables[Labour.EmployeeLeave]}" 
                        > 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewComboBoxColumn   
                                Header="Employee"   
                                DataMemberBinding="{Binding EmpNum, Mode=TwoWay}" 
                                SelectedValueMemberPath="EmpNum" 
                                DisplayMemberPath="Fullname" 
                                ItemsSource="{Binding}"   
                                DataContext="{Binding Tables[Labour.Employee]}"/>  
                <telerik:GridViewDataColumn Header="Leave Type" UniqueName="LeaveCode" /> 
                <telerik:GridViewDataColumn Header="Date From" UniqueName="DateFrom" /> 
                <telerik:GridViewDataColumn Header="Date To" UniqueName="DateTo" /> 
                <telerik:GridViewDataColumn Header="Hours" UniqueName="Hours" /> 
                <telerik:GridViewDataColumn Header="Pay In Advance" UniqueName="PayInAdvance"/>  
                <telerik:GridViewDataColumn Header="Comments" UniqueName="Comments" /> 
                <telerik:GridViewDataColumn Header="Total Made" UniqueName="TotalMade" /> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
    </Grid> 
</Window> 
 

 

 

 

 

Imports System.Data  
 
Class Window1  
 
    Public Sub New()  
        InitializeComponent()  
        Dim ds As New DataSet  
        Dim dt As New DataTable("Labour.Employee")  
        Me.BuildEmployeesTable(dt)  
        ds.Tables.Add(dt)  
        dt = New DataTable("Labour.EmployeeLeave")  
        Me.BuildEmployeeLeaveTable(dt)  
        ds.Tables.Add(dt)  
        Me.DataContext = ds  
    End Sub 
 
    Private Sub BuildEmployeesTable(ByVal dt As DataTable)  
        dt.Columns.Add("EmpNum"GetType(System.Int32))  
        dt.Columns.Add("Firstname"GetType(System.String))  
        dt.Columns.Add("Surname"GetType(System.String))  
        dt.Columns.Add("Fullname"GetType(System.String), "Firstname+' '+Surname")  
        Me.AdddEmployeesRow(dt, 1, "Joe""Blogs")  
        Me.AdddEmployeesRow(dt, 2, "John""Doe")  
        Me.AdddEmployeesRow(dt, 3, "Mary""May")  
    End Sub 
 
    Private Sub BuildEmployeeLeaveTable(ByVal dt As DataTable)  
        dt.Columns.Add("EmpNum"GetType(System.Int32))  
        dt.Columns.Add("LeaveCode"GetType(System.String))  
        dt.Columns.Add("DateFrom"GetType(System.DateTime))  
        dt.Columns.Add("DateTo"GetType(System.DateTime))  
        dt.Columns.Add("Hours"GetType(System.Int32))  
        dt.Columns.Add("PayInAdvance"GetType(System.Boolean))  
        dt.Columns.Add("Comments"GetType(System.String))  
        dt.Columns.Add("TotalMade"GetType(String), "Comments+Hours")  
        Me.AdddEmployeeLeaveRow(dt, 1, "sss", Now, Now, 55, True"comment")  
        Me.AdddEmployeeLeaveRow(dt, 2, "sss", Now, Now, 22, True"comment")  
        Me.AdddEmployeeLeaveRow(dt, 3, "sss", Now, Now, 33, True"comment")  
    End Sub 
 
    Private Sub AdddEmployeesRow(ByVal dt As DataTable, ByVal id As IntegerByVal fname As StringByVal lname As String)  
        Dim dr As DataRow = dt.NewRow()  
        dr("EmpNum") = id  
        dr("Firstname") = fname  
        dr("Surname") = lname  
        dt.Rows.Add(dr)  
    End Sub 
 
    Private Sub AdddEmployeeLeaveRow(ByVal dt As DataTable, ByVal id As IntegerByVal LeaveCode As StringByVal DateFrom As DateTime, ByVal DateTo As DateTime, ByVal Hours As IntegerByVal PayInAdvance As BooleanByVal Comments As String)  
        Dim dr As DataRow = dt.NewRow()  
        dr("EmpNum") = id  
        dr("LeaveCode") = LeaveCode  
        dr("DateFrom") = DateFrom  
        dr("DateTo") = DateTo  
        dr("Hours") = Hours  
        dr("PayInAdvance") = PayInAdvance  
        dr("Comments") = Comments  
        dt.Rows.Add(dr)  
    End Sub 
 
End Class 
 

Please offer some advice.

Regards,
Nic

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 03 Nov 2009, 01:43 PM
Hello Nic Roche,

I have tested  your code here and found the following solution :

Please change :
DataMemberBinding="{Binding EmpNum, Mode=TwoWay}"

to

DataMemberBinding="{Binding [EmpNum], Mode=TwoWay}"



Greetings,
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
Nic Roche
Top achievements
Rank 1
answered on 04 Nov 2009, 01:20 AM
Thanks Pavel. That worked.
Tags
GridView
Asked by
Nic Roche
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Nic Roche
Top achievements
Rank 1
Share this question
or