Bind WPF DataGrid column to indexed property in-VBForums
Results 1 to 6 of 6

Thread: Bind WPF DataGrid column to indexed property in

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    42

    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.

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,565

    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
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    42

    Re: Bind WPF DataGrid column to indexed property in

    Quote Originally Posted by Lightning View Post
    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.

  4. #4
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,565

    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
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2010
    Posts
    42

    Re: Bind WPF DataGrid column to indexed property in

    Quote Originally Posted by Lightning View Post
    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.

  6. #6
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,565

    Re: Bind WPF DataGrid column to indexed property in

    You could also use a converter, and pass the index as converterparameter
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.