Пример #1
0
        private void LoadDataMembers(CheckedListBoxSelector listSelector, object dataSource, object value)
        {
            listSelector.ListBox.Items.Clear();
            string v = value as string;
            if (v == null) v = "";
            string[] selected = v.Split(',');
            string dataMember = string.Empty;

            if (dataSource is Type)
            {
                try
                {
                    BindingSource source = new BindingSource();
                    source.DataSource = dataSource;
                    dataSource = source.List;
                }
                catch (Exception exception)
                {
                    if (IsCriticalException(exception))
                    {
                        throw;
                    }
                }
                catch
                {
                }
            }
            if (this.IsBindableDataSource(dataSource))
            {
                PropertyDescriptorCollection properties = GetItemProperties(dataSource, string.Empty);
                if (properties == null)
                    return;
                for (int i = 0; i < properties.Count; i++)
                {
                    PropertyDescriptor property = properties[i];
                    if (this.IsBindableDataMember(property))
                    {
                        string str = string.IsNullOrEmpty(dataMember) ? property.Name : (dataMember + "." + property.Name);
                        _ListSelector.ListBox.Items.Add(str, IsSelected(str,ref selected));
                    }
                }
                if (selected.Length > 1)
                {
                    for (int i = 0; i < selected.Length; i++)
                    {
                        string s1 = selected[i];
                        int i1 = _ListSelector.ListBox.Items.IndexOf(s1);
                        _ListSelector.ListBox.Items.RemoveAt(i1);
                        _ListSelector.ListBox.Items.Insert(i, s1);
                        _ListSelector.ListBox.SetItemChecked(i, true);
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the DataMembersSelector class.
 /// </summary>
 public DataMembersSelector()
 {
     _ListSelector = new CheckedListBoxSelector();
     _BindingContext = new BindingContext();
 }