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.
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 Integer, ByVal fname As String, ByVal 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 Integer, ByVal LeaveCode As String, ByVal DateFrom As DateTime, ByVal DateTo As DateTime, ByVal Hours As Integer, ByVal PayInAdvance As Boolean, ByVal 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