How to check checkbox programmatically

6 posts, 0 answers
  1. Alvin
    Alvin avatar
    6 posts
    Member since:
    Nov 2011

    Posted 08 Dec 2011 Link to this post

    Hi,

    Could you give me an example for how to check custom item checkBox programmatically.

    Thanks.

  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 12 Dec 2011 Link to this post

    Hi Alvin,

    Thank you for writing.

    As far as I understand, you want to check the RadCheckBoxElement. To achieve this, you can use the following code:

    radCheckBoxElement1.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On

    In case that you want to check ListView item, you should set the ListViewDataItem CheckState property to On:
    radListView1.Items[2].CheckState = Telerik.WinControls.Enumerations.ToggleState.On

    If this is not the case, then please describe your case in greater detail.

    I hope this helps.

    All the best,
    Peter
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alvin
    Alvin avatar
    6 posts
    Member since:
    Nov 2011

    Posted 15 Dec 2011 Link to this post

    Thanks for replying.

    I think I need to provide more information. What I want to do is to create custom items in RadListView from a list of objects.

    After I create the MyCustomVisualItem class (icon view),  I get my custom items created successfully and displayed in RadListView. A checkbox is showed with each custom item listed in RadListView. But how can I checked the checkbox programmatically right after the custom item iscreated.

    The code like following does not work

            Me.RadListView1.DataSource = myObjectList

            For i = 0 To Me.RadListView1.Items.Count - 1
                Me.RadListView1.Items(i).CheckState = Telerik.WinControls.Enumerations.ToggleState.On
            Next

    Another problem is every time I update the myObjectList and run Me.RadListView1.DataSource = myObjectList to re-create the custom items in RadListView again, the checkboxes that have been checked with cursor previously will be unchecked automatically. But CheckState of these checkboxes are still "On". Any solution for that?

    Thanks
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 19 Dec 2011 Link to this post

    Hi Alvin,

    The approach you have described in your last post should work correctly. This makes me think that there might be something wrong with your custom visual items. Therefore, I would kindly ask you to open a new support ticket and send me a sample project which demonstrates this scenario. This will let me investigate it and provide you a solution. Alternatively, you can post your full source code here on the forums.

    Generally, as I mentioned in a previous thread of yours, RadListView uses virtualization mechanism which means that the visual items stand for displaying the logical ones. At run time, each visual item is being detached and attached to different logical items so the check state should be kept in the data items.

    I am looking forward to hearing from you.

    Greetings,
    Ivan Todorov
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  6. Alvin
    Alvin avatar
    6 posts
    Member since:
    Nov 2011

    Posted 19 Dec 2011 Link to this post

    Thanks for reply.

    You are right, I double-checked my custom visual item class and found "MyBase.SynchronizeProperties()" was commented out in function SynchronizeProperties(). It works fine after I changed it back.

    Thanks
  7. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 21 Dec 2011 Link to this post

    Hello Alvin,

    I am glad that you have managed to sort this out.

    Should you need future help, do not hesitate to contact us.

    Kind regards,
    Ivan Todorov
    the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top
UI for WinForms is Visual Studio 2017 Ready