Determine if checkbox is selected

5 posts, 0 answers
  1. GM72
    GM72 avatar
    23 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post

    In the selection_changed event handler I want to be able to determine if the checkbox in the selected row has been selected.

    I don't seem to be able to do this? Please advise

    e.g.

     private void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)
            {
                var dataItem = e.AddedItems[0];
                bool checkBoxValue;
                if (dataItem != null)
                {
                    var selectedUIRow = RadGridView1.ItemContainerGenerator.ContainerFromItem(dataItem)
                        as Telerik.Windows.Controls.GridView.GridViewRow;
                    if (selectedUIRow != null)
                    {
                        var firstCell = selectedUIRow.Cells[3] as Telerik.Windows.Controls.GridView.GridViewCell;
                        if (firstCell != null)
                        {
                            // Get the value from the UI without knowing the type.
                            //checkBoxValue = (bool)firstCell.Value;
                        }
                    }
                }
            }

    firstcell.value returns the whole data entity... which is not what I want
  2. GM72
    GM72 avatar
    23 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post

    The above code works for any of the cells that are bound and I can access their natural values ie cell[1].value.

    Don't know why cell[3] (the checkbox cell) returns the whole data entity?
  3. Yoan
    Admin
    Yoan avatar
    1182 posts

    Posted 17 Sep 2012 Link to this post

    Hi Graeme,

     In order to determine if the checkbox is checked you can define properties in your business model and then define GridView's columns like : 

    <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Married}"/>
    </telerik:RadGridView.Columns>

    In the example, "Married" is of type bool, so the GridView will generate checkBox column by defaut. Then in selection_Changed event you can check the value of "Married" property is true or false. I would suggest you to work with the data objects instead of the visual elements. 

    In case that does not help you, please tell me what your exact scenario is.

    Greetings,
    Yoan
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  4. GM72
    GM72 avatar
    23 posts
    Member since:
    Sep 2012

    Posted 17 Sep 2012 Link to this post

    Hi Yoan,

    I understand what you are saying and this would work however I don't necessarily agree that I should be altering my domain model for this purpose.

    My purpose would be:

    User can select checkbox on a selection of rows out of the total rows
    User presses a commit button 
    For each of the selected rows a certain action will take place

    In my opinion this is view related logic.

    What I need is someway of selecting or marking multiple rows, then, when a button is pressed, identify which rows have been selected so as I can do something to them?
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Sep 2012 Link to this post

    Hello,

     You can use GridViewSelectColumn to select multiple items and you can use SelectedItems collection to check what is actually selected. 

    Greetings,
    Vlad
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Back to Top