I have requirement where I have to show a tree view with list of tables and if user selects any table then it should show a grid with list of columns & rows should have a DataGridCheckboxColumns, and user can edit the checkboxcolumns.
Currently I am facing technical challenges in performing this.
I'm able to create columns but rows are not getting displayed and more over on change of Tree View selection though I have the Datatable updated but if I assign to grid it is not reflected in UI. Please help me on this its really an emergency requirement.
Thanks in Advance. Please find the code snippet below.
//DataGrid Add Columns and Rows
private void DataGridInitialize(string tableName)
{
DataSet ds = selectionViewBAL.GetColumnNames(tableName);
DataSet dataset = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Functions");
dt.Columns.Add("AllColumns");
foreach (var row in ds.Tables[0].Rows)
{
string rowname = ((System.Data.DataRow)(row)).ItemArray[0].ToString();
dt.Columns.Add(rowname);
}
int i = 0;
foreach (DataColumn col in dt.Columns)
{
if (i == 0)
{
dataGrid1.Columns.Add(
new DataGridTextColumn
{
Header = "Functions",
Binding = new Binding(string.Format("[{0}]", "Functions"))
});
}
else
{
dataGrid1.Columns.Add(
new DataGridCheckBoxColumn
{
Header = col.ColumnName,
Binding = new Binding(string.Format("[{0}]", col.ColumnName))
});
}
i++;
}
DataSet fetchFunctionNames = new DataSet();
fetchFunctionNames = selectionViewBAL.GetListOfFunctions(); //FetchFunctions();
DataRow dr = dt.NewRow();
var itemsArray = new object[dataGrid1.Columns.Count];
for (int j = 0; j < fetchFunctionNames.Tables[0].Rows.Count; j++)
{
itemsArray[0] = fetchFunctionNames.Tables[0].Rows[j].ItemArray[1];
for (i = 1; i < itemsArray.Length; i++)
{
itemsArray[i] = true;
}
dr.ItemArray = itemsArray;
dt.Rows.Add(dr);
dr = dt.NewRow();
}
dataGrid1.DataContext = dt;
}
I'm able to see everything in dt, but I'm not able to assign the same to datagrid and I cant edit though.
<DataGrid Grid.Row="0" Grid.ColumnSpan="4" Grid.Column="1"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="7,9,0,0"
Name="dataGrid1" ItemsSource="{Binding}">