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

Adding checkbox to a gridview combo-box column

5 Answers 229 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Norbert John
Top achievements
Rank 1
Norbert John asked on 20 Aug 2010, 01:59 PM

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

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 20 Aug 2010, 02:06 PM
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
0
Norbert John
Top achievements
Rank 1
answered on 20 Aug 2010, 02:25 PM
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
0
Accepted
Maya
Telerik team
answered on 25 Aug 2010, 04:40 PM
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
0
Norbert John
Top achievements
Rank 1
answered on 27 Aug 2010, 05:39 AM
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
0
Afsal
Top achievements
Rank 1
answered on 18 Apr 2011, 07:06 PM
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
Tags
GridView
Asked by
Norbert John
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Norbert John
Top achievements
Rank 1
Maya
Telerik team
Afsal
Top achievements
Rank 1
Share this question
or