示例#1
0
        private void Load()
        {
            ListStore listStore = new ListStore(typeof(bool), typeof(string), typeof(BasePaymentType));

            for (int i = (int)BasePaymentType.Cash; i <= (int)BasePaymentType.Advance; i++)
            {
                BasePaymentType paymentType = (BasePaymentType)i;
                listStore.AppendValues(selected.Contains(paymentType),
                                       PaymentType.GetBasePaymentTypeName(paymentType), paymentType);
            }

            CellRendererToggle cellRendererToggle = new CellRendererToggle {
                Activatable = true
            };

            cellRendererToggle.Toggled += (sender, e) =>
            {
                TreeIter row;
                listStore.GetIter(out row, new TreePath(e.Path));
                bool            value       = !(bool)listStore.GetValue(row, 0);
                BasePaymentType paymentType = (BasePaymentType)listStore.GetValue(row, 2);
                if (value)
                {
                    selected.Add(paymentType);
                }
                else
                {
                    selected.Remove(paymentType);
                }
                listStore.SetValue(row, 0, value);
            };

            treeView.AppendColumn(string.Empty, cellRendererToggle, "active", 0);
            treeView.AppendColumn(string.Empty, new CellRendererText(), "text", 1);
            treeView.AppendColumn(string.Empty, new CellRendererText(), "text", 2).Visible = false;

            treeView.Model = listStore;
        }