This is a migrated thread and some comments may be shown as answers.

Need help on setting column attributes dyamically

4 Answers 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alessandro
Top achievements
Rank 1
Alessandro asked on 02 Nov 2010, 04:47 PM
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

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Nov 2010, 04:51 PM
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
0
Alessandro
Top achievements
Rank 1
answered on 02 Nov 2010, 05:06 PM
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
0
Dan Andrews
Top achievements
Rank 2
answered on 02 Nov 2010, 09:06 PM
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.
0
Vlad
Telerik team
answered on 03 Nov 2010, 07:51 AM
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
Tags
GridView
Asked by
Alessandro
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Alessandro
Top achievements
Rank 1
Dan Andrews
Top achievements
Rank 2
Share this question
or