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

Index binding

5 Answers 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hakki
Top achievements
Rank 1
Hakki asked on 29 Oct 2012, 04:42 PM
Hello,

I am setting up a grid for incoming data that is categorical. I do not know how many categories said data will have so it is dynamic. So I have set up something like this:

//if column got sent, put them in the grid alongside visit
                        Debug.Assert(Phpdata != null, "Phpdata != null");
                        if (Phpdata.ColumnCount != 0)
                        {
                            //populate grid for categorical data
                            Debug.Assert(Phpdata.Visit != null, "Phpdata.Visit != null");
                            for (var i = 0; i < Phpdata.Visit.GetLength(0); i++)
                            {
                                var ds = new Datas
                                    {
                                        VisitColumn = Phpdata.Visit[i],
                                        nColumn = Phpdata.n[i],
                                        PercentageColumn = Phpdata.Percentage[i]
                                    };
 
                                MyData.Add(ds);
                            }
 
                            //for each column create column n and column percentage
                            Debug.Assert(Phpdata != null, "Phpdata != null");
                            for (var c = 0; c < Phpdata.ColumnCount; c++)
                            {
                                var totalcolumn = new GridViewDataColumn
                                    {
                                        DataMemberBinding = new Binding("nColumn"),
                                        Header = Phpdata.ColumnName[c] + " [n]",
                                        UniqueName = "TotalColumn" + c
                                    };
 
                                var percentageColumn = new GridViewDataColumn
                                    {
                                        DataMemberBinding = new Binding("PercentageColumn"),
                                        Header = Phpdata.ColumnName[c] + " [%]",
                                        UniqueName = "PercentColumn" + c
                                    };
 
                                RadGrid.Columns.Add(totalcolumn);
                                RadGrid.Columns.Add(percentageColumn);
                            }

The problem is, this repeats the first data for each column. So I have tried something like this:

//same part as above just with binding changed
var percentageColumn =
new GridViewDataColumn
    {
        DataMemberBinding = new Binding("PercentageColumn[" + c + "]"),
        Header = Phpdata.ColumnName[c] + " [%]",
        UniqueName = "PercentColumn" + c
    };

But this return blank.

I have also tried:
DataMemberBinding = new Binding("Phpdata.Percentage[" + c + "]")
Which seems to have worked for Header but that too returned blank.

So how can I get the index of PercentageColumn, i.e: PercentageColumn[0] for first column and PercentageColumn[1] for second column etc so it binds to new data.

I am not even sure if I am going about the right way of handling dynamic columns but it made sense to me and I feel I am just missing the right syntax?

Thanks for any help/ideas!

5 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 01 Nov 2012, 03:47 PM
Hello,

Basically, this seems to be syntactically valid. Would you please check your Output for BindingExpressionPath errors? Would it be possible for you to mimic this behavior in a simple repro project that we can debug on our side?

Greetings,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Hakki
Top achievements
Rank 1
answered on 07 Nov 2012, 01:01 PM
Hello Ivan,

Thanks for your interest in helping me resolve this issue. You can find a sample project here:
~faulty file link edited out ~

Just to clarify grid should show:
- "Yes n" to be 6, "Yes %" to be 54.5
- "No n" to be 5, "No %" to be 45.5

Thanks again and looking forward to your response,
Hakki
0
Hakki
Top achievements
Rank 1
answered on 07 Nov 2012, 02:46 PM
My apologies for the faulty file above, here is a working one:

https://www.dropbox.com/s/57jwskc2q7ncw9f/DynamicColumns.zip
0
Accepted
Ivan Ivanov
Telerik team
answered on 12 Nov 2012, 12:44 PM
Hi,

I have succesfully managed to run your project. Would you please shed some more light on the follwoing matter: you are binding the RadGridView to an ObservableCollection<MyData> that has a single entry as seen on the attached "Watch" screenshot. Then you are binding two different columns to one and the same property. Apparently the same value is displayed in both columns. Shouldn't you use Collection types to define the DataView properties? I have modifed your project a bit. The updated version is attached for your reference.

Greetings,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Hakki
Top achievements
Rank 1
answered on 20 Nov 2012, 10:45 AM
Sorry for the delay just got around to actually testing this out. No light to shed I'm afraid, just a terrible oversight on my part there.

Your example project works perfectly and I have successfully applied it to my full project. Thanks a lot.
Tags
GridView
Asked by
Hakki
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Hakki
Top achievements
Rank 1
Share this question
or