WPF Data binding in DataGrid View vs 2008
window1.xaml code
<Window x:Class="WpfApplication4.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Loaded="Window_Loaded">
<Grid>
<my:WindowsFormsHost Margin="18,38,20,78" Name="windowsFormsHost1" >
<wf:DataGrid MouseEnter="DataGrid_MouseEnter" Name="myGrid">
</wf:DataGrid>
</my:WindowsFormsHost>
</Grid>
</Window>
window1.xaml.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace WpfApplication4
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SqlConnection con = new SqlConnection("data source = NIIT-A5314572E8; initial catalog = niit; integrated security = true");
SqlCommand cmd = new SqlCommand("select * from emp", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
((DataGrid)(windowsFormsHost1.Child)).DataSource = ds.Tables["Emp"];
}
private void DataGrid_MouseEnter(object sender, EventArgs e)
{
DataGrid obj = (DataGrid)(windowsFormsHost1.Child);
obj.AlternatingBackColor = System.Drawing.Color.Aquamarine;
obj.BackColor = System.Drawing.Color.Black;
obj.ForeColor = System.Drawing.Color.White;
}
}
}
No comments:
Post a Comment