简体   繁体   中英

Telerik RadGridView grouping

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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM