Need help on setting column attributes dyamically

5 posts, 0 answers
  1. Alessandro
    Alessandro avatar
    31 posts
    Member since:
    Oct 2010

    Posted 02 Nov 2010 Link to this post

    Hi I am binding the grid to a list of arbitrary objects. For isntance, the object might be Person

    class Person
    {
      bool: Selected {get; set;}
      string FirstName {get; set;}
      string LastName {get; set;}
    ...
    }

    I have auto column generation enabled so I'm not using any templates.

    I want all columns to be read-only except for the first which will be used to determine whether a row is selected or no (I have multiselect enabled).

    Do you have any suggestions on how to accomplish this? Perhaps set the binding mode to TwoWay and then loop through the columns making them readonly perhaps?

    -- x
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Nov 2010 Link to this post

    Hello Xavier,

     You can access auto-generated columns (and set various columns properties) using AutoGeneratingColumn event.

    Best wishes,
    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
  3. DevCraft banner
  4. Alessandro
    Alessandro avatar
    31 posts
    Member since:
    Oct 2010

    Posted 02 Nov 2010 Link to this post

    Vlad - Wow! That was fast. Thanks!

    Before I do use that approach, allow me to ask this.  Is there a way to determine the selected item (or items) when using the MVVM approach? I'm binding to an ObservableCollection.

     -- x
  5. Dan Andrews
    Dan Andrews avatar
    28 posts
    Member since:
    Jul 2009

    Posted 02 Nov 2010 Link to this post

    One way to store the selected value in the View-Model, is to make a reference object in the View-Model and use the Selection Change Event from the View to change the View-Model's reference object.

    public View()
    {
        InitializeComponent();
        this.GridView.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(GridView_SelectionChanged);
    }
    void GridView_SelectionChanged(object sender, SelectionChangeEventArgs e)
    {
        ((MyViewModel)this.DataContext).currentSelectedValue = ......
    }


    When I have a question about accessing the the V from the VM, I generally go back and see what I'm really trying to do.  Alternatively you can make a Command, but to be honest, I haven't done that yet.
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Nov 2010 Link to this post

    Hi guys,

    Please check this blog post for more info about selection and MVVM.  

    All the best,
    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
Back to Top
DevCraft banner