-
Feb 22nd, 2012, 02:58 AM
#1
Thread Starter
Member
Bind WPF DataGrid column to indexed property in
How to bind a DataGrid column to an indexed property in XAML?
My property which I try to bind is:
Code:
Private m_Correlations As New Dictionary(Of Integer, Double)
Public Property Correlations(ByVal key As Integer) As Double
Get
If m_Correlations.ContainsKey(key) Then
Return m_Correlations(key)
Else
Return Nothing
End If
End Get
Set(value As Double)
m_Correlations(key) = value
End Set
End Property
I have set the ItemsSource for the DataGrid to be my custom object.
Trying to bind the column to the first indexed item with
Code:
FieldName="Correlations[0]"
or
Code:
FieldName="Correlations(0)"
...doesn't work. The whole column appears with no data in it.
-
Feb 28th, 2012, 03:47 PM
#2
Re: Bind WPF DataGrid column to indexed property in
What comes to my mind is the create a separate property that contains the "first-item" in the collection, not very nice, but is should work
-
Feb 29th, 2012, 01:42 AM
#3
Thread Starter
Member
Re: Bind WPF DataGrid column to indexed property in
Originally Posted by Lightning
What comes to my mind is the create a separate property that contains the "first-item" in the collection, not very nice, but is should work
It will work but it doesn't solve my problem here.
I can of course make separate properties for each items, like
Correlation0
Correlation1
Correlation2
...
Correlation1000
This is not optimal however. Amount of those properties is determineded at runtime based on the underlying data. Therefore I prefer a collection here.
-
Feb 29th, 2012, 02:22 PM
#4
Re: Bind WPF DataGrid column to indexed property in
An other possibility, which might or might not work depending on the situation, is to use an itemslist / listbox / ... that binds to the collection
-
Mar 2nd, 2012, 06:26 AM
#5
Thread Starter
Member
Re: Bind WPF DataGrid column to indexed property in
Originally Posted by Lightning
An other possibility, which might or might not work depending on the situation, is to use an itemslist / listbox / ... that binds to the collection
I'm binding here a columns in the datadrig. UI cannot be changed here.
I have a datagrid that has x number of columns (amount of colulmns determined at runtime) and the corresponding custom object that has the equal number of properties.
-
Mar 2nd, 2012, 11:21 AM
#6
Re: Bind WPF DataGrid column to indexed property in
You could also use a converter, and pass the index as converterparameter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|