From 1e3c820c616e64f1cff80eeb7c533729187d6c8a Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Tue, 5 Apr 2022 18:50:48 +0300 Subject: [PATCH] Fixed set of ListView checked property --- demo/listViewDemo.go | 5 +++++ listView.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/demo/listViewDemo.go b/demo/listViewDemo.go index f2a36ac..f7724bf 100644 --- a/demo/listViewDemo.go +++ b/demo/listViewDemo.go @@ -36,6 +36,7 @@ GridLayout { DropDownList { row = 7, column = 1, id = listCheckboxVAlign, current = 0, items = ["top", "bottom", "center"]}, TextView { row = 8, text = "Checkbox horizontal align" }, DropDownList { row = 8, column = 1, id = listCheckboxHAlign, current = 0, items = ["left", "right", "center"]}, + Button { row = 9, column = 0:1, id = listSetChecked, content = "set checked 1,4,8" } ] } ] @@ -91,5 +92,9 @@ func createListViewDemo(session rui.Session) rui.View { rui.Set(view, "listView", rui.CheckboxHorizontalAlign, number) }) + rui.Set(view, "listSetChecked", rui.ClickEvent, func() { + rui.Set(view, "listView", rui.Checked, "1, 4, 8") + }) + return view } diff --git a/listView.go b/listView.go index 593e348..f8f620c 100644 --- a/listView.go +++ b/listView.go @@ -514,6 +514,18 @@ func (listView *listViewData) setChecked(value interface{}) bool { checked = []int{} } else { switch value := value.(type) { + case string: + checked = []int{} + for _, val := range strings.Split(value, ",") { + n, err := strconv.Atoi(strings.Trim(val, " \t")) + if err != nil { + invalidPropertyValue(Checked, value) + ErrorLog(err.Error()) + return false + } + checked = append(checked, n) + } + case int: checked = []int{value}