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

Binding data of a column to an array element

5 Answers 658 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ClausDC
Top achievements
Rank 1
Iron
ClausDC asked on 22 Sep 2010, 01:29 PM
If I use the following binding expression in a GridViewDataColumn

DataMemberBinding="{Binding Path=Days[1]}"

("Days" is an Array like Days[10])

I get the following error in the Visual Studio debug output window:

A first chance exception of type 'System.ArgumentException' occurred in Telerik.Windows.Data.dll

and the filter menu button in the column header is missing and the sorting function doesn't work anymore.

If I wrap the array element in a porperty in the business object and use this for binding, everything is fine. What's going on here?

Thanks

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 27 Sep 2010, 02:23 PM
Hello ClausDC,

Unfortunately, I am not capable of reproducing the issue you specified as your requirements and settings are not quite clear. What exactly is your scenario ? How do you define the array Days[ ] ? What is the reason you do not want to use a property for that particular column ? 
 

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ClausDC
Top achievements
Rank 1
Iron
answered on 27 Sep 2010, 03:04 PM

Consider the following (stripped-down):

I use the MVVM pattern.

The View contains a RadGridView with a few defined Columns in XAML like:

<

 

 

tk:RadGridView
ItemsSource="{Binding GridItems, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"

 

 

 

AutoGenerateColumns="False">

 

<

 

 

tk:RadGridView.Columns>

 


<
tk:GridViewDataColumn 
DataMemberBinding="{Binding Days[0]}"
UniqueName="Days1"
</tk:GridViewDataColumn>
  
<tk:GridViewDataColumn 
DataMemberBinding="{Binding Days[1]}"
UniqueName="Days2"
</tk:GridViewDataColumn>

...

</tk:RadGridView.Columns>
</tk:RadGridView>

In the ViewModel which acts as DataContext to the View I have the following property:
private ObservableCollection<BusinessClass1> _GridItems;
  
           public ObservableCollection<BusinessClass1> GridItems
        {
            get { return _GridItems; }
  
            set
            {
                _GridItems = value;
                OnPropertyChanged("GridItems");
  
            }
  
        }


Class BusinessClass1 consists of the following:

class BusinessClass1
{
  
private decimal[] _Days = new decimal[14];
         
public decimal[] Days
{
  get { return _Days; }
  set { _Days = value; }
}
  
}

I hope I could clarify my setup.
0
Maya
Telerik team
answered on 27 Sep 2010, 05:01 PM
Hi ClausDC,

I am still not quite sure what is the exact scenario you are trying to achieve so I am not able to provide you with any appropriate solution for the time being. I prepared a sample project using the code-snippet you provided. Please take a look at it and share more information if there is some misunderstanding according to your requirements.
 

Sincerely yours,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ClausDC
Top achievements
Rank 1
Iron
answered on 28 Sep 2010, 08:11 AM
I can't open your sample project because it does seem to use some Silverlight components and I'm not developing on Silverlight but on WPF.

Looking through your project files in an editor the example should produce the same issues I had, only the "GetDays()" call in the GridItems property getter in MyViewModel I'm not quite sure of. With "return _GridItems;" it would be more in line with my code.

I'll try to explain what I want to do again:

I want to bind column data of an GridView to elements of an array, i. e. array element with index 0 is bound to column1, array element with index 1 is bound to column 2 and so on. This works in WPF with the following notation: for example for a textbox:

<TextBox Text={Binding Path=Days[0]}></TextBox>

where Days[0] is element 1 in an array. If it works generally in WPF, it should work with your GridView, too, right?

But if I do this in that way (and you seem to get it in your sample project), I get the problems described in the first post (Filter Menu Button in column header dissapears, no sorting possible anymore ...). Strangely enough despite the problems, the data is displayed in the GridView.
0
Maya
Telerik team
answered on 01 Oct 2010, 09:31 AM
Hello ClausDC,

Firstly, please excuse me for the misunderstanding according to the type of Platform you are using.
I have modified the sample project so that it fits your requirements. Basically, the behavior you are getting of not being able to sort and filter the columns is not the expected one. We would investigate the issue and it has already been logged into our Public Issue Tracking System. You may follow its progress by its ID - 3611 - "RadGridView: No sorting/filtering functionality is enabled when the ItemsSource is type of decimal array".
As a possible workaround, I may suggest you to set the DataType Property of the column:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Days[0]}"
               Header="Day1"                                                      
               DataType="{x:Type system:Decimal}" />

Another possible approach may be to use a List instead of array.
     


Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
ClausDC
Top achievements
Rank 1
Iron
Answers by
Maya
Telerik team
ClausDC
Top achievements
Rank 1
Iron
Share this question
or