zhuxialiang 你好
将 System.Data.DataTable 作为 C1DataGrid 的数据源时,可以使用以下代码:
XAML代码:
- <Window x:Class="_9308_DataGrid.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="525" xmlns:my="http://schemas.componentone.com/wpf/DataGrid">
- <Grid>
- <my:C1DataGrid HorizontalAlignment="Left" Margin="18,18,0,0" Name="c1DataGrid1" VerticalAlignment="Top" ItemsSource="{Binding}" />
- </Grid>
- </Window>
复制代码
后台C#代码:
- 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;
- namespace _9308_DataGrid
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- c1DataGrid1.DataContext = GetData();
- }
- private System.Data.DataTable GetData()
- {
- System.Data.DataTable dt = new System.Data.DataTable();
- dt.Columns.Add("ID");
- dt.Columns.Add("Code");
- dt.Columns.Add("Name");
- dt.Rows.Add(1, "A10001", "Name_1");
- dt.Rows.Add(2, "A10002", "Name_2");
- dt.Rows.Add(3, "A10003", "Name_3");
- dt.Rows.Add(4, "A10004", "Name_4");
- dt.Rows.Add(5, "A10005", "Name_5");
- return dt;
- }
- }
- }
复制代码
|