Am I overcomplicating matters here?
-
This is related to a post I made yesterday, but after researching I think I found where my problem lies, and nevertheless am stuck again. The problem I have is the following. I read from a file data, this data consists of rows of 'x' columns (x changes from file to file). I want to display these rows in a list in my WPF application. Seems simple enough, might be simple, but as I am a beginner in WPF I might have chosen the most difficult possible way to get there... Since the row-makeup is completely file specific there's not much in the xaml file, just the declaration of the table-header:
<StackPanel x:Name="MyGridViewList" Orientation="Vertical"> <GridViewHeaderRowPresenter x:Name="grdViewHeader" ColumnHeaderContainerStyle="{StaticResource MyHeaderStyle}"/> </StackPanel>
In the code behind I read the column specific data and put it in the header.
GridViewColumnCollection colCollection = new GridViewColumnCollection(); for(int i=0;i<mydatacollection.columns.count;> { GridViewColumn viewCol = new GridViewColumn(); viewCol.Header = MyDataCollection.Columns\[i\].Name; viewCol.Width = 100; // I think here I have to add a line like: // viewCol.DisplayMemberBinding = bind to position i of the objectarray; colCollection.Add(viewCol); } grdViewHeader.Columns = colCollection;
The column-header is displayed correctly. Afterwards I create
GridViewRowPresenter
objects for each row, and to the Content property I assign an array of objects. The object at position 0 should be data for 1st column, object at pos 1 for 2nd etc... Right now the number of rows that's displayed is correct but the data in each cell is displayed as: "Object[] Array" So now I found out that theGridViewRowPresenter
does not know how to 'bind' each value to the right column. So in the commented out code above I need to mention somehow to bind to a specific position in the array. Can anyone tell me how to do this? Or am I doing it completely wrong here? Thanks for any help, Davy -
This is related to a post I made yesterday, but after researching I think I found where my problem lies, and nevertheless am stuck again. The problem I have is the following. I read from a file data, this data consists of rows of 'x' columns (x changes from file to file). I want to display these rows in a list in my WPF application. Seems simple enough, might be simple, but as I am a beginner in WPF I might have chosen the most difficult possible way to get there... Since the row-makeup is completely file specific there's not much in the xaml file, just the declaration of the table-header:
<StackPanel x:Name="MyGridViewList" Orientation="Vertical"> <GridViewHeaderRowPresenter x:Name="grdViewHeader" ColumnHeaderContainerStyle="{StaticResource MyHeaderStyle}"/> </StackPanel>
In the code behind I read the column specific data and put it in the header.
GridViewColumnCollection colCollection = new GridViewColumnCollection(); for(int i=0;i<mydatacollection.columns.count;> { GridViewColumn viewCol = new GridViewColumn(); viewCol.Header = MyDataCollection.Columns\[i\].Name; viewCol.Width = 100; // I think here I have to add a line like: // viewCol.DisplayMemberBinding = bind to position i of the objectarray; colCollection.Add(viewCol); } grdViewHeader.Columns = colCollection;
The column-header is displayed correctly. Afterwards I create
GridViewRowPresenter
objects for each row, and to the Content property I assign an array of objects. The object at position 0 should be data for 1st column, object at pos 1 for 2nd etc... Right now the number of rows that's displayed is correct but the data in each cell is displayed as: "Object[] Array" So now I found out that theGridViewRowPresenter
does not know how to 'bind' each value to the right column. So in the commented out code above I need to mention somehow to bind to a specific position in the array. Can anyone tell me how to do this? Or am I doing it completely wrong here? Thanks for any help, Davy