This is a migrated thread and some comments may be shown as answers.

How add text in dynamic columns

7 Answers 127 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Sharada
Top achievements
Rank 1
Sharada asked on 16 Dec 2010, 03:59 PM
Hi

I am using TreeListView.
I am adding columns dynamically.
How to acees the Row Cells to put value.
or how to add data to the dynamically generated coulms.

I want to manupulate the values before displaying in Row.

Thanks.

7 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 17 Dec 2010, 02:18 PM
Hello Sharada,

You do not add data to the columns or cells. Your business object should feed the new column.


Actually the common way to add dynamic columns follows the pattern below:

GridViewDataColumn col1=new GridViewDataColumn();
col1.Header="Column1";
col1.DataMemberBinding=new Binding("CustomProperty1");
....
this.radTreeListView1.Columns.Add(col1);

However if you need to access the autogenerated columns you may use AutoGeneratingColumn event, please read more about this here.

Greetings,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Jorge
Top achievements
Rank 1
answered on 23 Mar 2011, 10:09 AM
Hello Vanya,

I'm having the same issue here. I cannot do the Binding because the objects I'd like to show on the table can have a variant number (and thus names) of the properties.

So, what I'm trying to do, is to create this treeListView dinamycally, and I get to create all the columns I need. But then, I need to populate it with all the data from the objects. How can I do that without doing any binding?

Thank you very much,
Jorge
0
Vanya Pavlova
Telerik team
answered on 23 Mar 2011, 04:29 PM
Hi Jorge,

 
May you provide some more details on the topic ? How the RadTreeListView is bound to in your case?
As the RadTreeListView supports binding to a DataTable, you may give it a try.

Greetings,
Vanya Pavlova
the Telerik team
0
Jorge
Top achievements
Rank 1
answered on 23 Mar 2011, 04:58 PM
Hello Vanya,

Thank you for your quick response.

What I'm trying to do here is to display some properties of a set of objects into a TreeListView, so that user of my app can filter and search through them. But those objects will not be always the same: Their parameters to display will vary depending on some user input, so I cannot know beforehand which parameters I will need to display. That is why I cannot bind my TreeListView to any object, because I don't know beforehand which features this object should have.

What I was trying to do is to create a table dinamically. I got to create the set of columns fine, but I didn't know how to add rows and then fill the colmns content with the parameter's values.

I'll do some readings on this DataTable class you mention to see if this can suit my needs.

Thank you very much.
0
Jorge
Top achievements
Rank 1
answered on 24 Mar 2011, 11:56 AM
I got to do what I needed by using a DataTable, thank you very much Vanya.

I'm having a little trouble now, though.

I've binded a RowSelected event to mi TreeListView. Whenever this event is fired, my event handler function executes ok, but right after executing this function, an exception is thrown saying something like: The column '.' does not belong to the table 'TableName' (the datatable I bound to the TreeListView).

Is this a known bug? am I doing anything wrong?

This is what I'm doing to create the table:

DataTable table = new DataTable("GeometryProperties");
 
//Columns creation
for (int i = 1; i < ShowObject[0].Attributes.parameters.Count + 1; i++)
                {
 
                    string name = ShowObject[0].Attributes.parameters[i - 1].NAME;
 
                    /*DataColumn c = new DataColumn();
                    c.DataType = System.Type.GetType("System.String");
                    c.ColumnName = name;
                    c.AutoIncrement = false;
                    c.Caption = name;
                    c.ReadOnly = false;
                    c.Unique = false;
                    // Add the column to the table.
                    table.Columns.Add(c);
                }
 
//Rows creation
for (int j = 0; j < ShowObject.Count; j++)
                {
                    DataRow row = table.NewRow();
                    row["Geometry ID"] = ShowObject[j].Geometry.FID;
 
                    for (int k = 0; k < ShowObject[j].Attributes.parameters.Count; k++)
                    {
 
                        row[ShowObject[j].Attributes.parameters[k].NAME] = ShowObject[j].Attributes.parameters[k].VALUE;
                    }
 
                    table.Rows.Add(row);
                }
 
//Binding
this.radTreeListView.ItemsSource = table;
 
No parameter I'm setting as column name is named '.', so why might the TreeListView look for a '.' column on the table?

Should I open a new discussion topic for this issue?
0
Vanya Pavlova
Telerik team
answered on 24 Mar 2011, 01:27 PM
Hello Jorge,

 
May you verify which RadTreeListView's event you are currently using? RowLoaded, SelectionChanged or maybe I am missing something? I have spent some time researching such error types and I found that its is better to access the columns by indexes, when you are creating rows, rather that by name, you may get more information about this here. Using this snippet we are not able to reproduce this exception, I believe that the best option is to send us a small application in a new support ticket which we can use for local debugging.


Greetings,
Vanya Pavlova
the Telerik team
0
Jorge
Top achievements
Rank 1
answered on 25 Mar 2011, 11:35 AM
Hello Vanya,

I got to solve my problem by eliminating an incorrect binding in the XAML file I didn't know I had. Sorry for having bothered you with this problem.

Thanks again for the DataTable tip, it worked great!!
Tags
TreeListView
Asked by
Sharada
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Jorge
Top achievements
Rank 1
Share this question
or