Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Dynamically bind datatable to a dynamic datagrid

$
0
0

Using Visual C# 2010 Express, I have a primary data table dt. From this table I have to select few records depending on a filtering condition and load into a new datagrid of a new tab item in a Tab Control
I can create the new tab items but the associated datagrid has no records.

The tmpDt has records but the dgPred doesn't show any, why?

There's no designer xaml code for the dgPred. These are generated dynamically

foreach (DataRow dr in dt.Rows)
{
    mJobName = dr["job_name"].ToString();

    if (dr["res_type"].ToString() != "main") continue;

    IEnumerable<DataRow> tmpQuery = from row in dt.AsEnumerable()
        where row.Field<string>("res_type") == "pred" && row.Field<string>("job_name")==mJobName
        select row;

    DataTable tmpDt = tmpQuery.CopyToDataTable<DataRow>();

    DataGrid dgPred = new DataGrid();
    dgPred.Name = mJobName;
    dgPred.DataContext = tmpDt;
                                
    tabIndex = leftTabCtl.Items.Add(new TabItem()
    {
        Header = mJobName,
        Content = dgPred
    }
    );
}


Thanks,

-srinivas yelamanchili


sri



Viewing all articles
Browse latest Browse all 18858

Trending Articles