Home Forums WinForms controls Xceed Grid for WinForms Problem on dynamically creating a GridControl

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

    Hi there,

    Some days ago I came here asking for help on how to create a HeaderRow dynamically, André helped me but now I can’t test his solution because I am not being able to create the grid itself.

    Xceed.Grid.GridControl gridGap = new Xceed.Grid.GridControl();
    gridGap.Dock = DockStyle.Fill;

    gridGap.BeginInit();
    {
       ColumnManagerRow cmrHeader = new ColumnManagerRow();
       gridGap.FixedHeaderRows.Add(cmrHeader);
       ((ColumnManagerRow) gridGap.FixedHeaderRows[0]).AllowColumnReorder = true;

       //Here I add all the columns (I’m not showing all of them to keep this simple)
       gridGap.Columns.Add(new DataBoundColumn(“Name”));
                   
       gridGap.DataSource = dtbTableWithAllTheData;
       gridGap.DataMember = dtbTableWithAllTheData.TableName;
    }
    gridGap.EndInit();

    My problem?
    The DataSource is set and it has 3 rows. But the gridGap.DataRows doesn’t show them. gridGap.DataRows.Count returns zero.
    I dunno why but they are not binding….
    Am I forgeting something stupid ?

    Sorry for the disturbance.
    Thanks in Advance,
    Oscar

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

    User (Old forums)
    Member
    Post count: 23064

    The only thing I can think of is that your DataSet is empty.  I just tested this again on our side, and it works fine.

    Note that if you want to generate your columns yourself, you should to set the AutoCreateColumns property on the GridControl to false.  If you leave it to true (the default value), the gird will create all the columns automatically when you bind it.

     

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

    User (Old forums)
    Member
    Post count: 23064

    Hi André, thanks for your attention.

    I figured out the problem with you tip. My problem was that my DataSource was a DataTable and NOT a DataSet… Now I have it right!

    For improvements I tried out your Idea to set AutoCreateColumns to TRUE and delete the code that inserts manually all the columns and then use the SetDataBinding function. But it didn’t work.

    gridGap.BeginInit();
    {
        ColumnManagerRow cmrHeader = new ColumnManagerRow();
        gridGap.FixedHeaderRows.Add(cmrHeader);
        ((ColumnManagerRow) gridGap.FixedHeaderRows[0]).AllowColumnReorder = true;
     
        gridGap.AutoCreateColumns = true;
        gridGap.SetDataBinding(CurrentDataSet, CurrentTableName);
    }
    gridGap.EndInit(); 

    this code doesn’t work, it gives me zero in gridGap.DataRows.Count. To fix it I HAD to create the columns manually.
    To figure out what it could be, I tryed to creating columns manually with AutoCreateColumns true AND false and the result was the same…
    It seems that, for me, AutoCreateColumns isn’t working at all.
    Do you have any idea of what it could be?

    (The problem is solved, but this AutoCreateColumns not working tricked me)

    Thanks for the attention,
    Oscar

     

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

    User (Old forums)
    Member
    Post count: 23064

    Other thing,
    After creating all the columns I need to set a format to display each column’s data. In other places of my application (when I’m not creating the grid dynamically) the FormatSpecifier works fine, but now it doesn’t.

     Here is a code example

    gridGap.Columns.Add(new DataBoundColumn(“Exposition”));
    gridGap.Columns[“Exposition”].FormatSpecifier = “#,###,###,###,##0.0000 %”

    after that I use the following commands:

    gridGap.Dock = DockStyle.Fill;
    gridGap.ReadOnly = true;
    gridGap.RowSelectorPane.Visible = false;
    gridGap.AllowCellNavigation = false;              
    gridGap.ApplyStyleSheet(AssEstilo);

    gridGap.DataSource = AdsDadosGAPAtual;
    gridGap.DataMember = dtbTabelaAtual.TableName;

    Any ideas why the FormatSpecifier isn’t working?
    My data is displayed exacly as it is shown in my datasource…

     Thanks again!

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

    User (Old forums)
    Member
    Post count: 23064

    There seems to be something problematic in your project, because it should work fine to bind to a DataTable, and if you do not set the AutoCreateColumns, it should display all the columns included in the DataTable.  This is what I used when I mentioned I had tested this on our side.

    In the last snippet, you seems to be mixing the DataSet with the DataTable.  You should use one or the other.

    e.g.:

    grid.DataSource = dataSet;

    grid.DataMember = “nameOfTable”;

    or

    grid.DataSource = dataTable;

    grid.DataMember = dataTable.TableName;

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

    User (Old forums)
    Member
    Post count: 23064

    Hmmn,

    Interesting… I really dunno what could be happening to prevent the grid to be working fine… but I understood how it works, so it is fine.

     Do you have any idea to why the FormatSpecifier would be not working?

    Thanks again!

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

    User (Old forums)
    Member
    Post count: 23064

    Well, I wonder if you don’t have an exception that is swallowed by the grid or the .NET framework.

    Is the debugger set to break on all exceptions? (Debug Menu -> Exceptions -> Common Language Runtime Exception, then select “Break into the debugger” radio button in VS2003, or select “Thrown” CheckBox in VS2005/2008).

    If you are in VS2005/2008, make sure the “Enable Just My Code” CheckBox is unselected (Tools Menu -> Options -> Debugging -> General).

    This will make sure that no exceptions are swallowed by the grid or the framework, and that the debugger will break in any part of the code, not just yours.

    In fact, when leaving the AutoCreateColumns to true, and not providing the columns manually, the order in which you wrote you code should raise an exception, because you try to access a column that does not yet exist in the grid, when setting the FormatSpecifier.  You have to set the grid binding first, so the grid will create the columns, so you can access and set them after.

     

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

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