or
<t:RadGridView ItemsSource="{Binding Persons}" ActionOnLostFocus="CommitEdit" AutoGenerateColumns="False" > |
<t:RadGridView.Columns> |
<!-- Auto column --> |
<t:GridViewDataColumn DataMemberBinding="{Binding Path=ID}" /> |
<!-- Manual column --> |
<t:GridViewDataColumn DataMemberBinding="{Binding Name}"> |
<t:GridViewDataColumn.CellTemplate> |
<DataTemplate> |
<TextBlock Text="{Binding Name}" /> |
</DataTemplate> |
</t:GridViewDataColumn.CellTemplate> |
<t:GridViewDataColumn.CellEditTemplate> |
<DataTemplate> |
<TextBox Text="{Binding Name,Mode=TwoWay}" /> |
</DataTemplate> |
</t:GridViewDataColumn.CellEditTemplate> |
</t:GridViewDataColumn> |
</t:RadGridView.Columns> |
</t:RadGridView> |
using System.Collections.ObjectModel; |
using System.Windows; |
namespace WpfApplication2 |
{ |
/// <summary> |
/// Interaction logic for MainWindow.xaml |
/// </summary> |
public partial class MainWindow : Window |
{ |
public MainWindow() { |
InitializeComponent(); |
this.DataContext = this; |
} |
public ObservableCollection<Employee> Persons |
{ get { return EmployeeService.GetEmployees(); } } |
} |
public class Employee { |
public int ID { get; set; } |
public string Name { get; set; } |
} |
public class EmployeeService { |
public static ObservableCollection<Employee> GetEmployees() |
{ |
ObservableCollection<Employee> employees = new ObservableCollection<Employee>(); |
Employee employee = new Employee(); |
employee.Name = "Maria"; |
employee.ID = 24890; |
employees.Add(employee); |
employee = new Employee(); |
employee.Name = "Ana"; |
employee.ID = 23890; |
employees.Add(employee); |
employee = new Employee(); |
employee.Name = "Antonio"; |
employee.ID = 24890; |
employees.Add(employee); |
employee = new Employee(); |
return employees; |
} |
} |
} |
<!-- Window1.xaml --> |
<Window x:Class="WpfTelerikRadGridViewTest.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" Width="800" Height="600" > |
<Grid> |
<Grid.RowDefinitions> |
<RowDefinition /> |
<RowDefinition Height="Auto" /> |
</Grid.RowDefinitions> |
<telerik:RadGridView Name="radGridView1" ItemsSource="{Binding}" /> |
<Button Grid.Row="1" Click="ButtonBase_OnClick">Save</Button> |
</Grid> |
</Window> |
// Window1.xaml.cs |
public partial class Window1 |
{ |
public Window1() |
{ |
InitializeComponent(); |
var list = new ObservableCollection<string>(); |
list.Add("HELLO1"); |
list.Add("HELLO2"); |
list.Add("HELLO3"); |
list.Add("HELLO4"); |
list.Add("HELLO5"); |
DataContext = list; |
} |
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) |
{ |
var s = radGridView1.ToText(); |
} |
} |
<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" |
xmlns:telerikdata="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" |
Title="Window1" WindowState="Maximized"> |
<Grid> |
<telerik:RadGridView |
AutoGenerateColumns="False" |
HorizontalAlignment="Right" |
IsFilteringAllowed="False" |
CanUserFreezeColumns="False" |
CanUserReorderColumns="False" |
IsEnabled="True" |
ColumnsWidthMode="Auto" |
ShowColumnFooters="True" |
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" |
DataMemberBinding="{Binding [Hours], Mode=TwoWay}" > |
<telerik:GridViewDataColumn.AggregateFunctions> |
<telerikdata:SumFunction Caption="Total: " SourceField="Hours" /> |
</telerik:GridViewDataColumn.AggregateFunctions> |
</telerik:GridViewDataColumn> |
<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 |
RadDragAndDropManager.AddDragQueryHandler(...); |
RadDragAndDropManager.AddDragInfoHandler(...); |
RadDragAndDropManager.AddDropQueryHandler(..); |
RadDragAndDropManager.AddDropInfoHandler(...); |
In the Q3 release, the row only becomes selected when the user clicks on one of the cells in that row.