public void SetSelectedValue(NSComboBox combobox, object value)
            {
                var DisplayMember = cbox.DisplayMember;
                var ValueMember   = cbox.ValueMember;

                if (string.IsNullOrEmpty(DisplayMember))
                {
                    combobox.SelectItem(cbox.Items.IndexOf(value));
                    return;
                }
                combobox.SelectItem(cbox.Items.IndexOf(value));
            }
Example #2
0
			public ComboBoxImp(ComboBox owner)
			{
				this.owner = owner;

				combo = new NSComboBox();
				combo.Bordered = false;
				combo.UsesSingleLineMode = false;
				combo.LineBreakMode = NSLineBreakMode.Clipping;
				combo.BezelStyle = NSTextFieldBezelStyle.Rounded;
				combo.Alignment = NSTextAlignment.Natural;
				combo.Enabled = owner.Enabled;
				combo.Font = owner.Font.ToNSFont();
				combo.DoCommandBySelector = ComboDoCommandBySelector;
				combo.Changed += ComboTextFieldChanged;
				combo.WillPopUp += ComboWillPopUp;
				combo.WillDismiss += ComboWillDismiss;
				combo.Completes = true;
				combo.VisibleItems = 10;
				combo.UsesDataSource = true;
				combo.DataSource = this;
				combo.GetCompletions = ComboGetCompletions;

				if (owner.selected_index >= 0 && owner.selected_index < combo.Count)
					combo.SelectItem(owner.selected_index);
					
				combo.SelectionChanged += ComboSelectionChanged;
			}
Example #3
0
        public static void SelectByItem <T>(this NSComboBox comboBox, T obj, Func <T, T, bool> comparer = null)
        {
            if (comparer == null)
            {
                comparer = (x, y) => new GenericComparer().Compare(x, y) == 0;
            }
            int?index = null;

            if (obj == null)
            {
                // unselect if selecting null
                index = -1;
            }
            else if (comboBox.DataSource is ComboBoxDataSourceEx)
            {
                var dataSourceEx = ((ComboBoxDataSourceEx)comboBox.DataSource);
                var data         = dataSourceEx.Data;
                index = data.IndexOf(obj, (x, y) => comparer((T)x, (T)y));
                if (dataSourceEx.IncludeEmptyItem)
                {
                    index++;
                }
            }
            if (index.HasValue)
            {
                if (index.Value != -1)
                {
                    comboBox.SelectItem(index.Value);
                }
                else
                {
                    if (comboBox.SelectedIndex != -1)
                    {
                        comboBox.DeselectItem(comboBox.SelectedIndex);
                    }
                    comboBox.StringValue = string.Empty;
                }
            }
        }
Example #4
0
			public void SelectItem(int value)
			{
				combo.SelectItem(value);
			}
			public void SetSelectedValue (NSComboBox combobox, object value)
			{
				var DisplayMember = cbox.DisplayMember;
				var ValueMember = cbox.ValueMember;
				if (string.IsNullOrEmpty (DisplayMember))
				{
					combobox.SelectItem (cbox.Items.IndexOf (value));
					return;
				}
				combobox.SelectItem (cbox.Items.IndexOf (value));
				
			}
        // Shared initialization code
        private void Initialize()
        {
            AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;

            NSControlSize controlSize = NSControlSize.Small;

            propertyFilter = new NSSearchField(new CGRect(10, Frame.Height - 25, 170, 24))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                PlaceholderString = LocalizationResources.PropertyFilterLabel,
                ControlSize       = controlSize,
                Font = NSFont.FromFontName(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize),
            };
            AddSubview(propertyFilter);

            this.propertyArrangeModeLabel = new NSTextField(new CGRect(245, Frame.Height - 28, 150, 24))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = NSColor.Clear,
                TextColor       = NSColor.Black,
                Editable        = false,
                Bezeled         = false,
                StringValue     = LocalizationResources.ArrangeByLabel,
                ControlSize     = controlSize,
            };

            propertyArrangeMode = new NSComboBox(new CGRect(320, Frame.Height - 25, 153, 24))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Editable    = false,
                ControlSize = controlSize,
                Font        = NSFont.FromFontName(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize),
            };

            var enumValues = Enum.GetValues(typeof(PropertyArrangeMode));

            foreach (var item in enumValues)
            {
                propertyArrangeMode.Add(new NSString(item.ToString()));                    // TODO May need translating
            }
            propertyArrangeMode.SelectItem(0);

            if (IsArrangeEnabled)
            {
                AddSubview(this.propertyArrangeMode);
                AddSubview(this.propertyArrangeModeLabel);
            }

            // If either the Filter Mode or PropertySearchFilter Change Filter the Data
            propertyArrangeMode.SelectionChanged += OnArrageModeChanged;
            propertyFilter.Changed += OnPropertyFilterChanged;

            propertyTable = new FirstResponderOutlineView {
                RefusesFirstResponder   = true,
                AutoresizingMask        = NSViewResizingMask.WidthSizable,
                SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.None,
                HeaderView = null,
            };

#if DESIGNER_DEBUG
            propertyTable.GridStyleMask = NSTableViewGridStyle.SolidHorizontalLine | NSTableViewGridStyle.SolidVerticalLine;
#endif

            NSTableColumn propertiesList = new NSTableColumn(PropertyListColId)
            {
                Title = LocalizationResources.PropertyColumnTitle
            };
            NSTableColumn propertyEditors = new NSTableColumn(PropertyEditorColId)
            {
                Title = LocalizationResources.ValueColumnTitle
            };
            propertiesList.Width  = 158;
            propertyEditors.Width = 250;
            propertyTable.AddColumn(propertiesList);
            propertyTable.AddColumn(propertyEditors);

            // Set OutlineTableColumn or the arrows showing children/expansion will not be drawn
            propertyTable.OutlineTableColumn = propertiesList;

            // create a table view and a scroll view
            var tableContainer = new NSScrollView(new CGRect(10, Frame.Height - 210, propertiesList.Width + propertyEditors.Width, Frame.Height - 55))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            // add the panel to the window
            tableContainer.DocumentView = propertyTable;
            AddSubview(tableContainer);

            this.DoConstraints(new NSLayoutConstraint[] {
                propertyFilter.ConstraintTo(this, (pf, c) => pf.Top == c.Top + 3),
                propertyFilter.ConstraintTo(this, (pf, c) => pf.Left == c.Left + 10),

                propertyArrangeModeLabel.ConstraintTo(this, (pl, c) => pl.Top == c.Top + 5),
                propertyArrangeModeLabel.ConstraintTo(propertyArrangeMode, (pl, pa) => pl.Left == pa.Left - 71),

                propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Top == c.Top + 4),
                propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Left == c.Left + 280),
                propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Width == c.Width - 291),

                tableContainer.ConstraintTo(this, (t, c) => t.Top == c.Top + 30),
                tableContainer.ConstraintTo(this, (t, c) => t.Width == c.Width - 20),
                tableContainer.ConstraintTo(this, (t, c) => t.Height == c.Height - 40),
            });

            ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;

            UpdateTheme();
        }