Populate Cells in grid, without binding to dataset

10 posts, 0 answers
  1. Eduan Marais
    Eduan Marais avatar
    18 posts
    Member since:
    Feb 2010

    Posted 19 May 2010 Link to this post

    HI.

    I am building a grid in code, and needs to add rows ( and populate theirs cells ) in runtime.

    Creating the columns was easy, but I battle to edit the cell values.

    This is what I have tried.

    grid.Items.AddNew()  creates a new row in the grid. I would now like to assign a value to cell[0] in the new row.
    grid.Items[0] does not contain a method to access the cells.

    How do I get to the cells?

    I know that binding the grid to a datatable will be much easier, but I was hoping to access the cells directly, without having to create a table for the data first.

    Thx!

     

     

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 May 2010 Link to this post

    Hi Eduan Marais,

    RadGridView has a Property - ShowInsertRow that in case being set to "true", provides a special new row prompting you to add new row to the Grid. 
    I hope that helps, but in case I have misunderstood your requirements, please give me more details.


    Greetings,
    Maya
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Eduan Marais
    Eduan Marais avatar
    18 posts
    Member since:
    Feb 2010

    Posted 19 May 2010 Link to this post

    Hi Maya.

    Not exactly my problem, so let me rephrase.

    I need to populate a grid dynamically - all done in code. I will receive a dataset with information, but this information is not all relevant to the grid, so I can not bind directly to the dataset.
    So, I have to extract some of the data from the dataset, and add it to specific columns+Rows in the grid.
    I have to set values to specific cells. I can't find a way to do this, not sure if I am missing the point here.

    So, this is what I have done up to now.

    GridViewDataColumn col1 = new GridViewDataColumn();

     

    col1.UniqueName = "Column1";

    GridViewDataColumn col2 = new GridViewDataColumn();

     

    col2.UniqueName = "Column2";

     

    grid.Columns.Add(col1);
    grid.Columns.Add(col2);

    Great! So now I have 2 columns in my grid. I now add a row to the grid:
    grid.Items.AddNew();

    So now I have 2 columns and 1 row in my grid.
    I would now like to make the value on Column1, Row 1 equal to 5. I do not know how to do this, as I do not find a method to access the cell in the row.
    In other words, there is no grid.Items[0][0].value or something to get to the actual cell in the row.

    Please explain to me how to edit the value in the specific cell.

    Hope this is more clear.

    Thx!

  5. Eduan Marais
    Eduan Marais avatar
    18 posts
    Member since:
    Feb 2010

    Posted 20 May 2010 Link to this post

    Hi.

    I have seen an example on your documentation ( http://www.telerik.com/help/silverlight/gridview-managing-data-add-new-entries.html )
    that explains how to enter data in a grid.

    I have tried it, but still no data is displaying. I am starting to think that there is a property on the grid preventing me to see the data.
    This is what I have tried:

     

    GridViewCell cell = new GridViewCell();

     

    cell.Content = 100;

     

     

    GridViewRowItem item = new GridViewRowItem();

     

    item.Cells.Add(cell);

     

     

     

    this.grid.BeginInsert();

     

     

    this.grid.Items.Add(item);

     

     

    this.grid.CommitEdit();

    Even after explicitly beginning and insert and commiting it afterwards, the data still does not display.
    I have also noticed that I can not enter data into the grid once I am in runtime. The moment you exit the cell, it is cleared again. Makes me think that there are some extra properties that needs to be set for the cell to display its value.

    Regards

     

     
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 20 May 2010 Link to this post

    Hi,

    Can you post more info about what kind of benefits you expect from this approach (working with UI) versus working with collection of objects directly?

    Kind regards,
    Vlad
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Eduan Marais
    Eduan Marais avatar
    18 posts
    Member since:
    Feb 2010

    Posted 20 May 2010 Link to this post

    Well,
    I am not really thinking of benefits.
    I am receiving the data in a table that I can not bind directly to the grid, simply because it is not in the correct format. Each row coming from my dataset will represent 1 cell in the radgrid. So, I need to do some formatting on the idividual cells, based on the information received from the table - formatting like color and font size on cell level.

    I have done a lot of research the last 48 hours, and it seems to me that WPF recommends databinding, rather than manually populating the grid.
    So, if I do not get joy today, I will have to convert my data from the original table into a new datatable, bind the new datatable to the grid, and do the formatting afterwards.

    What do you recommend?
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 20 May 2010 Link to this post

    Hello,

    Generally the best approach will be MVVM. You can create a model where you can reformat the original data and bind the grid to some property of this model (new reformatted data). In this case you will have complete separation between the data and UI.

    Kind regards,
    Vlad
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Eduan Marais
    Eduan Marais avatar
    18 posts
    Member since:
    Feb 2010

    Posted 20 May 2010 Link to this post

    Hi.

    Thanks.
    I am not familiar with MVVM, but I will do some research on it.
    Thanks for the feedback!

    Eduan
  10. Gene
    Gene avatar
    64 posts
    Member since:
    Dec 2007

    Posted 25 Aug 2010 Link to this post

    Eduan,

    What approach did you end up taking on this?

    Best regards,
    Gene
  11. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 26 Aug 2010 Link to this post

    Hello Gene,

    Since RadGridView is a databound control , all possible solutions require some kind of view - a  view model , or just a small colelction of items that should serve as  ItemsSource for RadGridView.

    Feel free to share some more details on your business scenario and I will be glad to help you further .

    Greetings,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready