[GH-ISSUE #885] Beginner Question Regarding Checkbox #644

Open
opened 2026-03-04 01:06:43 +03:00 by kerem · 1 comment
Owner

Originally created by @daryl-williams on GitHub (Sep 11, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/885

I'm not sure if this is the right place to ask a newbie question, if there is a better place please let me know. I have a form with a number of checkboxes and I want to be able to set them all to checked when a button is clicked. I have some code as follows:

button := testForm.AddButton("Select all", func() {
    for i:=0; i<testForm.GetFormItemCount(); i++ {
      item := testForm.GetFormItem(i)
      //item.checked = true
      fmt.Printf("1. Item Type    = %T\n", item)
      fmt.Printf("2. Item Type    = %T\n", &item)
    }
}

I would like to be able to programmatically check each checkbox item. I have tried using item.SetChecked() but I am told:

item.SetChecked undefined (type tview.FormItem has no field or method SetChecked)

When I print out the item type of item I get *tview.CheckBox and when I print the type of &item I get *tview.FormItem and when I print the value (using %v) I get what appears to be a struct with 12 fields which is where I think the value I want to set resides.

Any help clearing this up would be appreciated, I have searched online and perused the demo code trying to find examples of how to work with checkboxes without much luck.

Regards,

Daryl

Originally created by @daryl-williams on GitHub (Sep 11, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/885 I'm not sure if this is the right place to ask a newbie question, if there is a better place please let me know. I have a form with a number of checkboxes and I want to be able to set them all to checked when a button is clicked. I have some code as follows: ``` button := testForm.AddButton("Select all", func() { for i:=0; i<testForm.GetFormItemCount(); i++ { item := testForm.GetFormItem(i) //item.checked = true fmt.Printf("1. Item Type = %T\n", item) fmt.Printf("2. Item Type = %T\n", &item) } } ``` I would like to be able to programmatically check each checkbox item. I have tried using item.SetChecked() but I am told: `item.SetChecked undefined (type tview.FormItem has no field or method SetChecked) ` When I print out the item type of `item` I get *tview.CheckBox and when I print the type of `&item` I get *tview.FormItem and when I print the value (using %v) I get what appears to be a struct with 12 fields which is where I think the value I want to set resides. Any help clearing this up would be appreciated, I have searched online and perused the demo code trying to find examples of how to work with checkboxes without much luck. Regards, Daryl
Author
Owner

@daryl-williams commented on GitHub (Sep 12, 2023):

@digitallyserviced

Thanks for your reply, I appreciate the explanation and the example code, it really helped me to understand the Go language better and helped me get that code working.

Regards

Daryl

<!-- gh-comment-id:1716628692 --> @daryl-williams commented on GitHub (Sep 12, 2023): @digitallyserviced Thanks for your reply, I appreciate the explanation and the example code, it really helped me to understand the Go language better and helped me get that code working. Regards Daryl
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#644
No description provided.