コード例 #1
0
        private void ComboBoxEx_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SelectedItem != null)
            {
                ComboBoxItemEx item = (ComboBoxItemEx)SelectedItem;

                if (_lastKey == null || item.ID != _lastKey)
                {
                    _lastKey = item.ID;

                    if (!publishing)
                    {
                        _controlHarness.SendXml(DeltaXml);
                    }
                }
            }
        }
コード例 #2
0
        public virtual void PublishData(XElement data)
        {
            publishing = true;
            _lastKey   = null;

            try
            {
                string selectedKey = null;

                if (SelectedItem != null && SelectedItem is ComboBoxItemEx)
                {
                    selectedKey = ((ComboBoxItemEx)SelectedItem).ID; // Cache the previously selected key, to reapply after the list is refilled
                }
                XElement ColumnDefintions = data.Element(Common.Data.Columns);
                XElement Rows             = data.Element(Common.Data.Rows);
                this.Items.Clear();

                if (Rows == null || ColumnDefintions == null)
                {
                    return;
                }

                string columnToUse = null;

                // Determine which column to display in the list
                if (!string.IsNullOrEmpty(DisplayTextColumn ?? DisplayMemberPath))
                {
                    // Use the column specified by the client
                    XElement displayColumn = ColumnDefintions.Elements(Common.Data.Column).Where(x => x.Attribute(Common.Data.ColumnField).Value == (DisplayTextColumn ?? DisplayMemberPath)).FirstOrDefault();

                    if (displayColumn != null)
                    {
                        columnToUse = displayColumn.GetAttributeValue(Common.IDAttrib);
                    }
                }
                else
                {
                    // Use the first *string* column that has a width
                    XNode columnNode = ColumnDefintions.FirstNode;

                    while (columnToUse == null && columnNode != null)
                    {
                        if (columnNode is XElement)
                        {
                            XElement element  = (XElement)columnNode;
                            int      theWidth = 0;

                            string dataType = element.GetAttributeValue(Common.Datatypes.AttribName);

                            if (element.Attribute(Common.Data.ColumnWidth) != null)
                            {
                                int.TryParse(element.Attribute(Common.Data.ColumnWidth).Value, out theWidth);
                            }

                            if (theWidth != 0 && dataType == Common.Datatypes.String)
                            {
                                columnToUse = element.Attribute(Common.IDAttrib).Value;
                            }
                        }

                        columnNode = columnNode.NextNode;
                    }
                }

                // Always add an empty or null entry
                if (_showNullEntry.HasValue && _showNullEntry.Value)
                {
                    ComboBoxItemEx nullItem = new ComboBoxItemEx("", Common.Null);
                    nullItem.Content    = NullEntryText;
                    nullItem.Background = this.Background;
                    this.Items.Add(nullItem);
                }

                _dictionary = new Dictionary <string, ComboBoxItemEx>();
                XNode node = Rows.FirstNode;

                while (node != null)
                {
                    if (node is XElement)
                    {
                        XElement       rowData       = (XElement)node;
                        string         id            = rowData.Attribute(Common.IDAttrib).Value;
                        string         type          = rowData.GetAttributeValue(Common.Data.RowType);
                        ComboBoxItemEx item          = new ComboBoxItemEx(id, type);
                        XElement       displayColumn = rowData.Elements("Cell").Where(x => x.Attribute("id").Value == columnToUse).FirstOrDefault();

                        if (displayColumn != null)
                        {
                            item.Content = displayColumn.Value;

                            if (id.Length == 0)
                            {
                                id = displayColumn.Value;
                            }
                        }

                        this.Items.Add(item);
                        _dictionary.Add(item.ID.ToString(), item);
                    }

                    node = node.NextNode;
                }

                if (selectedKey != null)
                {
                    SelectKey(selectedKey); // Select the previously selected key
                }
            }
            finally
            {
                publishing = false;
            }
        }
コード例 #3
0
        public virtual void PublishData(XElement data)
        {
            publishing = true;
            _lastKey = null;

            try
            {
                string selectedKey = null;

                if (SelectedItem != null && SelectedItem is ComboBoxItemEx)
                    selectedKey = ((ComboBoxItemEx)SelectedItem).ID; // Cache the previously selected key, to reapply after the list is refilled

                XElement ColumnDefintions = data.Element(Common.Data.Columns);
                XElement Rows = data.Element(Common.Data.Rows);
                this.Items.Clear();

                if (Rows == null || ColumnDefintions == null)
                    return;

                string columnToUse = null;

                // Determine which column to display in the list
                if (!string.IsNullOrEmpty(DisplayTextColumn ?? DisplayMemberPath))
                {
                    // Use the column specified by the client
                    XElement displayColumn = ColumnDefintions.Elements(Common.Data.Column).Where(x => x.Attribute(Common.Data.ColumnField).Value == (DisplayTextColumn ?? DisplayMemberPath)).FirstOrDefault();

                    if (displayColumn != null)
                        columnToUse = displayColumn.GetAttributeValue(Common.IDAttrib);
                }
                else
                {
                    // Use the first *string* column that has a width
                    XNode columnNode = ColumnDefintions.FirstNode;

                    while (columnToUse == null && columnNode != null)
                    {
                        if (columnNode is XElement)
                        {
                            XElement element = (XElement)columnNode;
                            int theWidth = 0;

                            string dataType = element.GetAttributeValue(Common.Datatypes.AttribName);

                            if (element.Attribute(Common.Data.ColumnWidth) != null)
                                int.TryParse(element.Attribute(Common.Data.ColumnWidth).Value, out theWidth);

                            if (theWidth != 0 && dataType == Common.Datatypes.String)
                                columnToUse = element.Attribute(Common.IDAttrib).Value;
                        }

                        columnNode = columnNode.NextNode;
                    }
                }

                // Always add an empty or null entry
                if (_showNullEntry.HasValue && _showNullEntry.Value)
                {
                    ComboBoxItemEx nullItem = new ComboBoxItemEx("", Common.Null);
                    nullItem.Content = NullEntryText;
                    nullItem.Background = this.Background;
                    this.Items.Add(nullItem);
                }

                _dictionary = new Dictionary<string, ComboBoxItemEx>();
                XNode node = Rows.FirstNode;

                while (node != null)
                {
                    if (node is XElement)
                    {
                        XElement rowData = (XElement)node;
                        string id = rowData.Attribute(Common.IDAttrib).Value;
                        string type = rowData.GetAttributeValue(Common.Data.RowType);
                        ComboBoxItemEx item = new ComboBoxItemEx(id, type);
                        XElement displayColumn = rowData.Elements("Cell").Where(x => x.Attribute("id").Value == columnToUse).FirstOrDefault();

                        if (displayColumn != null)
                        {
                            item.Content = displayColumn.Value;

                            if (id.Length == 0)
                                id = displayColumn.Value;
                        }

                        this.Items.Add(item);
                        _dictionary.Add(item.ID.ToString(), item);
                    }

                    node = node.NextNode;
                }

                if (selectedKey != null)
                    SelectKey(selectedKey); // Select the previously selected key
            }
            finally
            {
                publishing = false;
            }
        }