开发者

datagrid in a datagrid cell

开发者 https://www.devze.com 2023-01-06 03:36 出处:网络
hey how can i put a datagrid inside other datagrid cell 4ex- i have a cut开发者_Python百科omer colum with a collapse sign(or button) now when i click on the sign(or button) a new datagrid is polpulate

hey how can i put a datagrid inside other datagrid cell 4ex- i have a cut开发者_Python百科omer colum with a collapse sign(or button) now when i click on the sign(or button) a new datagrid is polpulated on the same row next column with customer details .

can any one point how it can be done?


quite simple...

public partial class Window1 : Window
    {
        DataTable dt = new DataTable();
        public Window1()
        {
            InitializeComponent();
            dt.Columns.Add("AA", typeof(string));
            dt.Columns.Add("BB", typeof(string));
            dt.Columns.Add("CC", typeof(string));
            dt.Rows.Add("11", "22");
            dt.Rows.Add("22", "33");
            dt.Rows.Add("33", "44");
            dataGrid1.ItemsSource = dt.DefaultView;
            this.dataGrid1.RowDetailsVisibilityChanged += new EventHandler<Microsoft.Windows.Controls.DataGridRowDetailsEventArgs>(datagrid1_RowdetailsVisibilityChanged);  

        }

        void datagrid1_RowdetailsVisibilityChanged(object sender, Microsoft.Windows.Controls.DataGridRowDetailsEventArgs e)
        {
            Microsoft.Windows.Controls.DataGrid innerDataGrid = e.DetailsElement as Microsoft.Windows.Controls.DataGrid;
            innerDataGrid.ItemsSource = ((IListSource)dt).GetList();
        }

in xaml file write the code

        <my:DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <my:DataGrid Name="datagrid2"></my:DataGrid>
            </DataTemplate>
        </my:DataGrid.RowDetailsTemplate>
    </my:DataGrid>
</Grid>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号