or
<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
I am trying to databing a datatable result in XAML (declarative databinding). I tried it programmatically and it does work by setting the Itemsource of my radcarousel to the datatable in code. Can you please tell me where i am going wrong with my ObjectDataProvider.
XAML code:
<Window x:Class="TelerikCarousel.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:carousel="clrnamespace:Telerik.Windows.Controls.Carousel;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telerikT="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
xmlns:local="clr-namespace:TelerikCarousel" |
Title="Window1" Height="800" Width="800" Background="DarkBlue"> |
<Window.Resources> |
<ObjectDataProvider x:Key="objectDataProvider" ObjectType="{x:Type local:Window1}" MethodName="InserRow" /> |
</Window.Resources> |
<Grid> |
<Grid.RowDefinitions> |
<RowDefinition Height="280*" /> |
<RowDefinition Height="482*" /> |
</Grid.RowDefinitions> |
<Grid.Resources> |
<!-- removed the carousel stylings so it could be shorter but it does work --> |
</GridResources> |
<telerik:RadCarousel Margin="19,51,22,293" Name="radCarousel1" ItemsSource="{Binding Source={StaticResource objectDataProvider}}" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > |
</telerik:RadCarousel> |
</Grid> |
</Window> |
using System; |
using System.Windows; |
using System.Windows.Media; |
using System.Windows.Shapes; |
using System.Data.SqlClient; |
using System.Data; |
using Telerik.Windows.Controls; |
namespace TelerikCarousel |
{ |
/// <summary> |
/// Interaction logic for Window1.xaml |
/// </summary> |
public partial class Window1 : Window |
{ |
public Window1() |
{ |
InitializeComponent(); |
//object itemsSource = radCarousel1.ItemsSource; |
this.radCarousel1.Loaded += new RoutedEventHandler(radCarousel1_Loaded); |
} |
void radCarousel1_Loaded(object sender, RoutedEventArgs e) |
{ |
Path path = CreateLinePath(); |
RadCarouselPanel panel = this.radCarousel1.FindCarouselPanel(); |
panel.ItemsPerPage = 5; |
panel.Path = path; |
this.radCarousel1.ReflectionSettings.Visibility = Visibility.Visible; |
this.radCarousel1.ReflectionSettings.Opacity = 0.5; |
} |
private Path CreateLinePath() |
{ |
Path newPath = new Path(); |
PathFigureCollectionConverter figureConverter = new PathFigureCollectionConverter(); |
object geometryFigures = figureConverter.ConvertFromString("M30,347 L307.5,347"); |
PathGeometry newGeometry = new PathGeometry(); |
newPath.Stretch = Stretch.Fill; |
BrushConverter brushConverter = new BrushConverter(); |
newPath.Stroke = (Brush)brushConverter.ConvertFromString("#FF0998f8"); |
newPath.StrokeThickness = 2; |
newGeometry.Figures = (PathFigureCollection)geometryFigures; |
newPath.Data = (Geometry)newGeometry; |
return newPath; |
} |
//public DataSet dataset = new DataSet("MedSpaImage"); |
public DataTable dt = new DataTable("Medxx"); |
public DataTable InserRow() |
{ |
string myConnectionstring = ""; |
if (myConnectionstring == "") |
{ |
myConnectionstring = "Initial Catalog=MedSpa;Data Source=4DBQR61\\IMSERVER;Integrated Security=True"; |
} |
try |
{ |
SqlConnection myConnection = new SqlConnection(myConnectionstring); |
string myInsertQuery = "SELECT * FROM Testing"; |
SqlCommand myCommand = new SqlCommand(myInsertQuery); |
myCommand.Connection = myConnection; |
SqlDataAdapter adapter = new SqlDataAdapter(); |
myConnection.Open(); |
adapter.SelectCommand = new SqlCommand(myInsertQuery, myConnection); |
adapter.Fill(dt); |
myCommand.ExecuteNonQuery(); |
myCommand.Connection.Close(); |
} |
catch (Exception ex) |
{ |
MessageBox.Show(ex.ToString()); |
} |
return dt; |
} |
} |
} |