I am trying to define a select column on a grid view as I saw in your example
1. how this column can be bind ?
2. how is the header is set to a checkbox like in your example, I get some text instead of a checbox, according to your example it looks like you don't need to do anything in order to get this behaviour
Ron
15 Answers, 1 is accepted
Currently this column does not support binding. Could you please give us more information about the functionality that you would like to implement? I guess that there is a property on the data items (for exmaple, IsSelected) that you would like to bind the selected column to. If that is the case you could use a workaround - subscribe to the SelectionChanged event and update the respective data item properties when selection changes. For example:
private void cmbViews_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (MyDataType selectedItem in e.AddedItems) { selectedItem.IsSelected = true; } foreach (MyDataType deselectedItem in e.RemovedItems) { selectedItem.IsSelected = false; } }Regards,
Milan
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.
this is somthing that I have tried, and decided to this instead:
instead of using the built-in selectColumn, I have create a template column which holds a checkbox and that checkbox is bound to some property.
my question now is:
when the user checks the checkbox I want the rows to be selected, the problem is that I could not find any way to get the current row object when checking the checkbox, I have tried using the Checked and Click events on the checbox, but this does not help since it returns a reference to the cehckbox
how can I get a refernece to the row that holds the checkbox?
Ron
You can use ParentOfType<GridViewRow>() to achieve this. For example:
var checkBox = (CheckBox)sender;
var row = checkBox.ParentOfType<GridViewRow>();
This method is an extension method part of Telerik.Windows.Controls namespace.
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.
another question:
I have a button that is used to check\uncheck checkbox on the gird
since I have a checkbox in each row of the grid, I running on all of them and check them simply ny lopping on Gird.Items
the problem I have seen is that if the grid contains a scroll them all the item which are down (I need to scroll) are not cehcked
How can I solve this?
Ron
If this CheckBox is bound to some property of your business objects why not change the property of the object 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.
I've just tried this however everything worked fine on my end. Please check the attached project for reference.
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.
I have tried to use your example, but still O ahve prolbems.
I have made some changes in your example to be a like my project
please try to see what I did wrong there
since I can not upload my files to here
here is the MainPage,xaml.cs
using
System.Windows.Controls;
using
System.Collections;
using
System.Linq;
using
System.Collections.Generic;
using
System.ComponentModel;
using
Telerik.Windows.Controls;
using
Telerik.Windows.Controls.GridView;
namespace
SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
//this.dg1.ItemsSource = from i in Enumerable.Range(0, 1000)
// select new MyObject() { ID = i };
MyObject obj = new MyObject();
this.DataContext = obj;
this.dg1.ItemsSource = obj.GridItem;
}
private void CheckBox_Click(object sender, System.Windows.RoutedEventArgs e)
{
//StringbUI
var grid = ((CheckBox)sender).ParentOfType<GridViewDataControl>();
//List<
foreach(MyObjec2 o in dg1.Items)
{
o.IsChecked = ((
CheckBox)sender).IsChecked.Value;
}
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
//this.dg1.ItemsSource = from i in Enumerable.Range(0, 1000)
// select new MyObject() { ID = i };
}
}
public class MyObject : INotifyPropertyChanged
{
public MyObject()
{
Load();
}
//public int ID { get; set; }
private List<MyObjec2> _gridItems;
//bool _MyProperty;
//public bool MyProperty { get { return _MyProperty; } set { _MyProperty = value; OnPropertyChanged("MyProperty"); } }
#region
INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void Load()
{
_gridItems =
new List<MyObjec2>();
for (int i = 0; i < 1000; i++)
{
_gridItems.Add(
new MyObjec2() { Name = "Ron" + i.ToString(), Phone = "12345", IsChecked = false });
}
GridItem = GridItem;
}
public List<MyObjec2> GridItem
{
get { return this._gridItems; }
set
{
this._gridItems = value;
OnPropertyChanged(
"GridItem");
}
}
#endregion
}
public class MyObjec2
{
public string Name
{
get;
set;
}
public string Phone
{
get;
set;
}
public bool IsChecked
{
get;
set;
}
}
}
here is MainPage.xaml
<
UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="40" ></RowDefinition>
<RowDefinition Height="200"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Content="clieck me" Click="Button_Click"></Button>
<telerikGrid:RadGridView x:Name="dg1" Grid.Row="1" AutoGenerateColumns="False">
<telerikGrid:RadGridView.Columns>
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding IsChecked}">
<telerikGrid:GridViewDataColumn.Header>
<CheckBox Click="CheckBox_Click" />
</telerikGrid:GridViewDataColumn.Header>
<telerikGrid:GridViewDataColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" />
</DataTemplate>
</telerikGrid:GridViewDataColumn.CellTemplate>
</telerikGrid:GridViewDataColumn>
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Name}" />
</telerikGrid:RadGridView.Columns>
</telerikGrid:RadGridView>
</Grid>
</
UserControl>
If you want your TwoWay Binding to work normally you need to raise PropertyChanged.
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.
You should raise PropertyChanged in property setter.
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.
and it still does not work
Nothing will raise PropertyChange in your IsChecked property - you have simple auto-property:
public bool IsChecked
{
get;
set;
}
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.
I ddi not notice that
