Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Am I overcomplicating matters here?

Am I overcomplicating matters here?

Scheduled Pinned Locked Moved WPF
helpwpfcsharpdata-structurestutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GDavy
    wrote on last edited by
    #1

    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 the GridViewRowPresenter 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

    C 1 Reply Last reply
    0
    • G GDavy

      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 the GridViewRowPresenter 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

      C Offline
      C Offline
      ColinM123
      wrote on last edited by
      #2

      How about using the new datagrid in the wpf toolkit? http://www.codeplex.com/wpf[^] This can autogenerate columns, not sure if it will solve your problem though!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups