Reputation: 1
I have RadGridView
in my Winforms
application and i want to group my files so i use this:
RadGridView radGridView1;
DataTable table = null;
radGridView1.ShowColumnHeaders = false;
radGridView1.ShowGroupPanel = false;
radGridView1.ShowRowHeaderColumn = false;
radGridView1.AllowAddNewRow = false;
radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
radGridView1.GroupDescriptors.Add(new Telerik.WinControls.Data.GroupDescriptor("File"));
private void AddFile(string file)
{
table = new DataTable();
table.Columns.Add("Protocol", typeof(string));
table.Columns.Add("Property Value1", typeof(string));
table.Columns.Add("File", typeof(string));
table.Rows.Add("File size:", "", file);
table.Rows.Add("File duration:", "", file);
table.Rows.Add("Creation time:", "", file);
radGridView1.DataSource = table;
}
My problem is that after the first file was chosen and added so in the next file - nothing happen and i think it's because the table i already have same A column names.
Upvotes: 0
Views: 2199
Reputation: 3402
You should create the DataTable
and do the Column.Add()
once, Right now you're creating a new table for every file and you replace the old table every time.
It should look like this:
RadGridView radGridView1;
DataTable table = new DataTable();
table.Columns.Add("Protocol", typeof(string));
table.Columns.Add("Property Value1", typeof(string));
table.Columns.Add("File", typeof(string));
radGridView1.ShowColumnHeaders = false;
radGridView1.ShowGroupPanel = false;
radGridView1.ShowRowHeaderColumn = false;
radGridView1.AllowAddNewRow = false;
radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
radGridView1.GroupDescriptors.Add(new Telerik.WinControls.Data.GroupDescriptor("File"));
radGridView1.DataSource = table;
private void AddFile(string file)
{
table.Rows.Add("File size:", "", file);
table.Rows.Add("File duration:", "", file);
table.Rows.Add("Creation time:", "", file);
}
Upvotes: 1