Home Forums WinForms controls Xceed Grid for WinForms Dynamically creating a HeaderRow

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16586 |

    Hi there,

    I’m kind of embaressed to ask this but I see no other way to solve this since I can’t find an answer to my problem on the internet.
    Actually it is something very simple but I’m not being able to do it.

    I’ve a DataTable that came from my database and then binded it to an Xceed Grid through DataSource

     Ex: myXceedGrid.DataSource = Mytable;

    Now, my problem is that when I test it I’ve noticed that it doesn’t show the header row with the title of each column. To solve this problem I thought that it would be easy, something like myGrid.HeaderRows.Add(“Column1”, “Column2″…) But that isn’t possible.

     I tried creating a DataRow and add DataCells with the column names but I keep getting an error that tells me that it is not possible to add something to a ReadOnly or FixedSize row… I setted ReadOnly to False and it didn’t work. Didn’t find a FixedSize property though…

     Well… that is my problem…
    What I need is just a way to solve this… or an explanation/code to create a headerRow dynamically.

    Could anyone help me ?
    Thanks in advance.

    Imported from legacy forums. Posted by Oscar (had 1159 views)

    User (Old forums)
    Member
    Post count: 23064

    Simply use the ColumnManagerRow class :

    ColumnManagerRow managerRow = new ColumnManagerRow();

    gridControl1.FixedHeaderRows.Add( managerRow );

    BTW, an easy way to find out how to do things in code is to do it through the designer in a sample project, and look at the code that is generated.  Then reproduce this code in your actual project.

     

    Imported from legacy forums. Posted by André (had 364 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi André,

    I tried to do what you’ve told me to, but I’m getting the readonly or fixed size error.
    Here, take a look at my code

    ColumnManagerRow cmrHeader = new ColumnManagerRow(); // Header Row
    MyGrid.FixedHeaderRows.Add(cmrHeader);

    //Reading the column names from the table and copying to the header row
    foreach (System.Data.DataColumn col in dtbActualTable.Columns)
    {
       if (MyResource.ResourceManager.GetString(col.ColumnName) != null)
       {
          if (col.ColumnName == “Tax”)
          {
              Xceed.Grid.DataCell cell = new Xceed.Grid.DataCell(“Tax (% a.a.)”);
              cmrHeader.Cells.Add(cell); // ERROR: Cannot add an item to a ReadOnly or FixedSize list.
              cell.Value = “Tax (% a.a.)”;
          }
         else
         {
              //Here i tried a different method.
              cmrHeader.Cells.Add(new Xceed.Grid.DataCell(MyResource.ResourceManager.GetString(col.ColumnName))); // ERROR: Same error above
         }
      }
    }

    Do you know what am I doing wrong ?
    Thanks in advance
    Oscar

    Imported from legacy forums. Posted by Oscar (had 424 views)

    User (Old forums)
    Member
    Post count: 23064

    Only add the two lines of code I provided, and remove everything else you added in your code.  When calling the ColumnManagerRow constructor, it will automatically create all the ColumnManagerCell’s for the corresponding columns present in the gird.  Remember that when binding the grid, it automatically creates the columns that correspond to those present in the data source.

    Imported from legacy forums. Posted by André (had 314 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you for your attention andré! I’ll try to do that as soon as I get my GridControl working.

    Since I’m having a problem with another thing I’ll create another topic about it
    This is the link,
    http://xceed.com/CS/forums/16817/ShowThread.aspx#16817

    Thanks again André!

    Imported from legacy forums. Posted by Oscar (had 1047 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.