Adding checkbox to a gridview combo-box column

6 posts, 1 answers
  1. Norbert John
    Norbert John avatar
    16 posts
    Member since:
    Dec 2009

    Posted 20 Aug 2010 Link to this post

    Hi,

        I have a GridViewComboBoxColumn bound to a datasource. I need to add a checkbox on the first row. How can we achieve this? Please help.

    Thanks in advance,
    Norbert John

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 20 Aug 2010 Link to this post

    Hello Norbert John,

    I can not quite understand what exactly are you trying to achieve.
    Please share a bit more info on the expected appearance and behavior and I will be glad to assist you further.

    Can you please mock up the expected UI appearance ( e.g. in excel) and send me the screenshot. I am sure we can think of something .

    Kind regards,
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Norbert John
    Norbert John avatar
    16 posts
    Member since:
    Dec 2009

    Posted 20 Aug 2010 Link to this post

    Hello Pavel Pavlov,
     
    My requirement is like, I have a grid with combobox columns as shown in the attachment. Each of combobox contains 3 values Audit, Review and None. The first row( shown in red border in attachment), is expected to be a checkbox. On selecting the checkbox all the rows of that column should change to 'Audit'.

    If we cannot place a check box, combo-box is fine. But the top combobox should display only 'Audit'. Currenlty it is displaying all the 3 values as of other rows since column is bound to a datasource. How can we filter the items in the combobox in top row?

    NB: Columns are generated dynamically using XMLDataSource. This is because number of columns are not fixed. Kindly let me know if the requirement is not clear.


    Thanks in Advance,
    Norbert John
  5. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Aug 2010 Link to this post

    Hi Norbert John,

    In order to meet your requirements, you can use the RowLoaded event of the grid, find the first row and predefine the ContentTemplate of its cell in the GridViewComboBoxColumn. For example:

    void RadGridView1_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
    {
        var rows = this.RadGridView1.ChildrenOfType<GridViewRow>();
        foreach(GridViewRow row in rows)
        {
            if(this.RadGridView1.ItemContainerGenerator.IndexFromContainer(row) == 0)
            {
             row.Cells[2].ContentTemplate = (DataTemplate)this.Resources["CheckBoxCell"];
           }
        }      
    }

    Afterwards, you can handle the Checked event of the CheckBox and set the item to be displayed in the ComboBox for each row. For example:
    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        CheckBox checkBox = sender as CheckBox;        
        if(checkBox.IsChecked == true)
        {
            foreach(Person person in this.RadGridView1.ItemsSource as ObservableCollection<Person>)
            {
                person.CountryID = 1;
            }
        }
    }

    I am sending you a sample project so that you can use it as a reference.


    Regards,
    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
  6. Norbert John
    Norbert John avatar
    16 posts
    Member since:
    Dec 2009

    Posted 27 Aug 2010 Link to this post

    Hello Maya,

    The solution provided by you worked. Thanks for your prompt reply. We had an alternate solution too by setting the content of the cell. This is executed in the rdgView_RowLoaded event.
    Dim objCheckBox As New CheckBox
    objCheckBox.Name = "CheckBox1"
    objCheckBox.DataContext = e.DataElement
    RemoveHandler objCheckBox.Click, AddressOf CheckBoxHandler
    AddHandler objCheckBox.Click, AddressOf CheckBoxHandler
    e.Row.Cells(4).Content = objCheckBox


    Thanks and Regards,
    Norbert John
  7. Afsal
    Afsal avatar
    24 posts
    Member since:
    Dec 2010

    Posted 18 Apr 2011 Link to this post

    I am using latest version of telerik controls. I used the same code. In the first row i can see the checkbox control. But at the same time
    if we click on corner or top of any cell in the first row the dropdown list displays. Is there any workaround for this issue?
    Or is there any new ways to implement the same using later telerik controls?

    with thanks and regards,
    Afsal
Back to Top
UI for WPF is Visual Studio 2017 Ready