using System.Data;
namespace WpfApplication1
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Firstname");
dt.Columns.Add("Lastname");
DataRow dr = dt.NewRow();
dr["Firstname"] = "allen";
dr["Lastname"] = "coww";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Firstname"] = "allen";
dr["Lastname"] = "coww";
dt.Rows.Add(dr);
dg.ItemsSource = dt.DefaultView;
}
private void dg_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 选择行,这个事件会被激活
}
}
//
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">