示例#1
0
        /// <summary>Initializes a new instance of the <see cref="ListItemRenderer"/> class.</summary>
        /// <param name="control">The control that owns this renderer.</param>
        /// <param name="defaultImage">The default image for each item.</param>
        public ListItemRenderer(ListControl control, Image defaultImage)
        {
            if (control == null) throw new ArgumentNullException("control");

            _control = control;
            _defaultImage = defaultImage;
        }
示例#2
0
        public static void SetSelectedListControlItem(ListControl ctrl, string PropertyName, object ValueToSelect)
        {
            bool iscbox = false;
            bool islbox = false;
            if ((ctrl as ComboBox) != null)
                iscbox = true;
            if ((ctrl as ListBox) != null)
                islbox = true;

            if (iscbox)
            {
                foreach (var item in (ctrl as ComboBox).Items)
                {
                    if (ObjectInspector.GetObjectPropertyValue(item, PropertyName).Equals(ValueToSelect))
                    {
                        (ctrl as ComboBox).SelectedItem = item;
                        break;
                    }
                }
            }

            if (islbox)
            {
                foreach (var item in (ctrl as ListBox).Items)
                {
                    if (ObjectInspector.GetObjectPropertyValue(item, PropertyName).Equals(ValueToSelect))
                    {
                        (ctrl as ComboBox).SelectedItem = item;
                        break;
                    }
                }
            }
        }
示例#3
0
 private void Rebind(ListControl control, IList datasource)
 {
     // HACK: Rebinding the datasource like this is dirty, a better approach is to use the BindingSource Class [http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx]
     // Sopme drawbacks are that you can only add 1 item at a time, since it does not expose a AddRange Method. As well as it forces the code to talk to the winforms controls directly.
     control.DataSource = null;
     control.DataSource = datasource;
 }
 public static void DataBind(Type enumType, ListControl control, object targetObject, string propertyName)
 {
     if (enumType == null)
     {
         throw new ArgumentNullException("enumType");
     }
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (targetObject == null)
     {
         throw new ArgumentNullException("targetObject");
     }
     if (string.IsNullOrEmpty(propertyName))
     {
         throw new ArgumentNullException(propertyName);
     }
     IList dataSource = EnumHelper.ToList(enumType);
     control.DataSource = dataSource;
     control.DisplayMember = "Value";
     control.ValueMember = "Key";
     PropertyInfo propInfo = targetObject.GetType().GetProperty(propertyName);
     if (propInfo == null)
     {
         throw new ApplicationException("The targetObject doesn't contains a property named " + propertyName);
     }
     control.SelectedValue = propInfo.GetValue(targetObject, null);
     control.SelectedValueChanged += delegate(object sender, EventArgs e)
     {
         propInfo.SetValue(targetObject, control.SelectedValue, null);
     };
 }
示例#5
0
文件: Util.cs 项目: sim0629/negirc
 public static void addItem(ListControl list, string text)
 {
     if (list == null || text == null || text == "") return;
     if (list.InvokeRequired)
         list.Invoke(new textHandler(uaddItem), list, text);
     else uaddItem(list, text);
 }
        public ToolStripOptionsToolbarSection(ListControl listControl)
            : base(listControl)
        {
            _listControl = listControl;

            _toolStrip = new ToolStrip();
            _toolStrip.AutoSize = true;
            _toolStrip.Visible = false;
            _toolStrip.Anchor = AnchorStyles.None;
            _toolStrip.Dock = DockStyle.None;
            _toolStrip.GripStyle = ToolStripGripStyle.Hidden;
            _toolStrip.TabIndex = 0;
            _toolStrip.Text = "List options";
            _toolStrip.CanOverflow = true;
            _toolStrip.Renderer = new MyRenderer();
            _toolStrip.BackColor = Color.Transparent;
            _toolStrip.Layout += _toolStrip_Layout;
            AddDefaultToolStripButtons();
            _toolStrip.CreateControl();

            listControl.Controls.Add(_toolStrip);

            listControl.Columns.GroupedItems.DataChanged += GroupedItems_DataChanged;
            HandleEnablingGroupButtons();
        }
 public static void LoadMineName(ListControl lb, String selectedText
     = "")
 {
     var mines = Mine.FindAll();
     if (mines != null)
         DataBindListControl(lb, mines, "name",
      "id", selectedText);
 }
 public static void LoadHorizontalName(ListControl lb, int mineId,
     String selectedText = "")
 {
     var horizontals = Horizontal.FindAllByProperty("mine.id", mineId);
     if (horizontals != null)
         DataBindListControl(lb, horizontals, "name",
             "id", selectedText);
 }
 public static void LoadTunnelName(ListControl lb, int workingFaceId,
     String selectedText = "")
 {
     var tunnels = Tunnel.FindAllByProperty("workingface.id", workingFaceId);
     if (tunnels != null)
         DataBindListControl(lb, tunnels, "name", "id",
             selectedText);
 }
示例#10
0
 public static void LoadWorkingFaceName(ListControl lb, int
     miningAreaId, String selectedText = "")
 {
     var workingFaces =
         Workingface.FindAllByProperty("mining_area.id", miningAreaId);
     if (workingFaces != null)
         DataBindListControl(lb, workingFaces, "name",
             "id", selectedText);
 }
示例#11
0
文件: MainForm.cs 项目: dizar888/News
        private void BindUsersToListBox(ListControl listBox)
        {
            listBox.DataSource = null;
            listBox.DataSource = UsersServiceHelper.UpdateAndGetUsers();
            listBox.DisplayMember = "Login";
            listBox.ValueMember = "Id";

            grpUserInfo.Enabled = UsersServiceHelper.SelectedUser != null && UsersServiceHelper.SelectedUser.IsDeleted == "False";
        }
示例#12
0
 public static void LoadMiningAreaName(ListControl lb, int
     horizontalId, string selectedText = "")
 {
     var miningAreas =
         MiningArea.FindAllByProperty("horizontal.id", horizontalId);
     if (miningAreas != null)
         DataBindListControl(lb, miningAreas, "name",
             "id", selectedText);
 }
示例#13
0
        private static void SetCombo(ListControl combo, string culture)
        {
            combo.SelectedValue = culture;

            // best match
            if (combo.SelectedValue == null)
            {
                combo.SelectedValue = culture.Split('-')[0];
            }
        }
示例#14
0
 public ListSection( ListControl listControl )
     : base(listControl)
 {
     _headerSection = Host.SectionFactory.CreateHeaderSection( listControl, listControl.Columns.VisibleItems );
     _headerSection.LayoutController = this;
     listControl.Columns.GroupedItems.DataChanged += GroupedItems_DataChanged;
     Host.FocusedSection = this; // we handle row focus manually from here.
     Children.Add( _headerSection );
     ExcludeFirstChildrenFromVScroll = 1;
     listControl.SelectedItems.DataChanged += SelectedItems_DataChanged;
 }
示例#15
0
 public void BindControl(System.Windows.Forms.ListControl ctl)
 {
     myControl = ctl;
     if (ctl is ComboBox)
     {
         ComboBox cbo = (ComboBox)ctl;
         if (this.BoxSize.Height > 0)
         {
             cbo.DrawMode     = DrawMode.OwnerDrawVariable;
             cbo.MeasureItem += new MeasureItemEventHandler(HandleMeasureItem);
             cbo.DrawItem    += new DrawItemEventHandler(HandleDrawItem);
             cbo.ItemHeight   = this.BoxSize.Height + 5;
         }
         else
         {
             cbo.DrawMode = DrawMode.Normal;
         }
         System.Collections.IEnumerable items = this.GetItems();
         if (items != null)
         {
             foreach (object obj in items)
             {
                 cbo.Items.Add(obj);
             }
         }
     }
     else if (ctl is ListBox)
     {
         ListBox lst = (ListBox)ctl;
         if (this.BoxSize.Height > 0)
         {
             lst.DrawMode     = DrawMode.OwnerDrawVariable;
             lst.ItemHeight   = this.BoxSize.Height + 5;
             lst.MeasureItem += new MeasureItemEventHandler(HandleMeasureItem);
             lst.DrawItem    += new DrawItemEventHandler(HandleDrawItem);
         }
         else
         {
             lst.DrawMode = DrawMode.Normal;
         }
         System.Collections.IEnumerable items = this.GetItems();
         if (items != null)
         {
             foreach (object obj in items)
             {
                 lst.Items.Add(obj);
             }
         }
     }
 }
示例#16
0
        private void lstWebServiceEndpoint_SelectedIndexChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.ListControl realSender = (System.Windows.Forms.ListControl)sender;
            string selectedUri       = realSender.Text;
            WebServiceCollection wsc = _mySession.WebServicesCollectionsHydrated[new Uri(selectedUri)];

            this._currentWsc = wsc;
            this.lstWebServices.Items.Clear();
            this.lstMethods.Items.Clear();
            this.lstParameters.Items.Clear();
            foreach (WebService ws in wsc.WebServices)
            {
                this.lstWebServices.Items.Add(ws.Name);
            }
        }
示例#17
0
 private static void BindList(Win.ListControl listControl, MDataTable source)
 {
     try
     {
         if (source.Columns.Count > 0)
         {
             listControl.DataSource    = new MDataView(ref source);
             listControl.ValueMember   = source.Columns[0].ColumnName;
             listControl.DisplayMember = source.Columns[source.Columns.Count > 1 ? 1 : 0].ColumnName;
         }
     }
     catch (Exception err)
     {
         Log.WriteLogToTxt(err);
     }
 }
示例#18
0
        //*************************************************************************
        //  Method: PopulateWithEnumValues()
        //
        /// <summary>
        /// Populates a ListControl with all values in an enumeration.
        /// </summary>
        ///
        /// <param name="oListControl">
        /// ListControl to populate.
        /// </param>
        ///
        /// <param name="oEnumType">
        /// Enumeration to populate the ListControl with.
        /// </param>
        ///
        /// <param name="bFormatForUser">
        /// If true, spaces are inserted between each word in the enum values, and
        /// the values are sorted alphabetically.  The value
        /// "DaysActiveInNewsgroup" gets displayed as "Days active in newsgroup",
        /// for example.  If false, the values are displayed as is
        /// ("DaysActiveInNewsgroup", for example), and no sorting is done.
        /// </param>
        ///
        /// <remarks>
        /// This method populates a ListControl with all values in an enumeration.
        /// The user sees the string version of each value in the list.  The
        /// <see cref="ListControl.SelectedValue" /> property returns the selected
        /// value in the enumeration.
        /// </remarks>
        //*************************************************************************
        public static void PopulateWithEnumValues(
            ListControl oListControl,
            Type oEnumType,
            Boolean bFormatForUser
            )
        {
            Debug.Assert(oListControl != null);

            // Get an array of values in the enumeration.

            Array aoEnumValues = Enum.GetValues(oEnumType);
            Int32 iEnumValues = aoEnumValues.Length;

            // Create an array of ObjectWithText objects.

            ArrayList oObjectWithText = new ArrayList(iEnumValues);

            for (Int32 i = 0; i < iEnumValues; i++)
            {
            Object oEnumValue = aoEnumValues.GetValue(i);
            String sEnumString = oEnumValue.ToString();

            if (bFormatForUser)
            {
                sEnumString = EnumUtil.SplitName(sEnumString,
                    EnumSplitStyle.FirstWordStartsUpperCase);
            }

            oObjectWithText.Add( new ObjectWithText(oEnumValue, sEnumString) );
            }

            if (bFormatForUser)
            oObjectWithText.Sort();

            // Tell the ListControl which properties on the objects in the array
            // should be used.

            oListControl.DisplayMember = "Text";
            oListControl.ValueMember = "Object";

            // Populate the ListControl.

            oListControl.DataSource = oObjectWithText;
        }
示例#19
0
 private static void applyNewDataSource(ListControl container, object dataSource, int count)
 {
     int index = container.SelectedIndex;
     container.DataSource = null;
     container.DataSource = dataSource;
     if (count == 0)
     {
         index = -1;
     }
     else if (index < 0)
     {
         index = 0;
     }
     else if (index >= count)
     {
         index = count - 1;
     }
     container.SelectedIndex = index;
 }
示例#20
0
        private void lstMethods_SelectedIndexChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.ListControl realSender = (System.Windows.Forms.ListControl)sender;
            string name = realSender.Text;
            Method ws   = null;

            foreach (Method myMethod in this._currentWs.Methods)
            {
                if (name.Equals(myMethod.Name))
                {
                    this._currentMethod = myMethod;
                    this.lstParameters.Items.Clear();
                    foreach (Parameter p in myMethod.Parameters)
                    {
                        lstParameters.Items.Add(p.ToString());
                    }
                }
            }
        }
示例#21
0
        private void lstWebServices_SelectedIndexChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.ListControl realSender = (System.Windows.Forms.ListControl)sender;
            string     name = realSender.Text;
            WebService ws   = null;

            foreach (WebService myWs in this._currentWsc.WebServices)
            {
                if (name.Equals(myWs.Name))
                {
                    this._currentWs = myWs;
                    this.lstMethods.Items.Clear();
                    this.lstParameters.Items.Clear();
                    foreach (Method m in myWs.Methods)
                    {
                        lstMethods.Items.Add(m.Name);
                    }
                }
            }
        }
    InitializeListControl
    (
        ListControl listControl
    )
    {
        Debug.Assert(listControl != null);

        ListControlUtil.PopulateWithObjectsAndText(listControl,
            new Object [] {

            ImageFormat.Bmp, "BMP (.bmp)",
            ImageFormat.Gif, "GIF (.gif)",
            ImageFormat.Jpeg, "JPEG (.jpg)",
            ImageFormat.Png, "PNG (.png)",
            ImageFormat.Tiff, "TIFF (.tif)"
            }

            );

        listControl.SelectedValue = ImageFormat.Jpeg;
    }
 // this adds the string of values to a single dropdown
 private void PopulateControl(List<string> values, ListControl target)
 {
     if (target is ListBox)
     {
         ListBox control = (ListBox)target;
         foreach (string value in values)
             control.Items.Add(value);
     }
     else
     {
         ComboBox control = (ComboBox)target;
         foreach (string value in values)
             control.Items.Add(value);
     }
 }
示例#24
0
				public ObjectComparer (ListControl owner)
				{
					this.owner = owner;
				}
        private List<string> GetValuesFromDB(string query, ListControl control)
        {
            List<string> values = new List<string>();

            if (control is ComboBox)
                values.Add("");

            using (OdbcConnection conn = new OdbcConnection(connectionString))
            {
                conn.Open();

                OdbcCommand comm = new OdbcCommand(query, conn);

                OdbcDataReader reader = comm.ExecuteReader();

                while (reader.Read())
                {
                    switch (Type.GetTypeCode(reader.GetFieldType(0)))
                    {
                        case TypeCode.Decimal:
                            values.Add(reader.GetDecimal(0).ToString());
                            break;
                        case TypeCode.Double:
                            values.Add(reader.GetDouble(0).ToString());
                            break;
                        case TypeCode.String:
                            values.Add(reader.GetString(0).ToString());
                            break;
                        case TypeCode.Int32:
                            values.Add(reader.GetInt32(0).ToString());
                            break;
                    }
                }
            }

            return values;
        }
示例#26
0
 public ItemArray(ListControl listControl)
 {
     _listControl = listControl;
     _entries     = new List <Entry>();
 }
示例#27
0
				public ObjectComparer(ListControl owner)
				{
					this.owner = owner;
				}
示例#28
0
        /// <summary>
        /// Gets the item data.
        /// </summary>
        /// <param name="lstControl">The list control instance.</param>
        /// <param name="index">The index.</param>
        /// <returns>The item data.</returns>
#if TargetF2
        public static int GetItemData(System.Windows.Forms.ListControl lstControl, int index)
示例#29
0
        /// <summary>
        /// Adds the item.
        /// </summary>
        /// <param name="lstControl">The list control instance.</param>
        /// <param name="value">The value.</param>
#if TargetF2
        public static void AddItem(System.Windows.Forms.ListControl lstControl, string value)
示例#30
0
        /// <summary>将实体信息添充至ListControl</summary>
        /// <param name="entity"></param>
        /// <param name="field"></param>
        /// <param name="control"></param>
        private void SetListControl(IEntity entity, FieldItem field, ListControl control)
        {
            Type type = field.Type;
            Object value = entity[field.Name];

            if (type == typeof(int))
                control.SelectedIndex = (int)value;
            else
            {
                control.SelectedValue = value;

                if (control.SelectedIndex == -1)
                {
                    if (control is ListBox)
                    {
                        (control as ListBox).SelectedItem = value;
                    }
                    else if (control is ComboBox)
                    {
                        (control as ComboBox).SelectedItem = value;
                    }
                }
            }
        }
示例#31
0
        /// <summary>
        /// Sets the item data.
        /// </summary>
        /// <param name="lstControl">The list control instance.</param>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
#if TargetF2
        public static void SetItemData(System.Windows.Forms.ListControl lstControl, int index, int value)
示例#32
0
 public ItemArray(ListControl listControl)
 {
     _listControl = listControl;
 }
示例#33
0
 protected int CrossThreadGetSelectedIndex(ListControl c)
 {
     if (this.InvokeRequired)
     {
         CrossThreadGetSelectedIndexDelegate d = new CrossThreadGetSelectedIndexDelegate(this.CrossThreadGetSelectedIndex);
         return (int)this.Invoke(d, new Object[] { c });
     }
     else
     {
         return c.SelectedIndex;
     }
 }
示例#34
0
        void AddItem(TextBox tb, ListControl lb)
        {
            IList items = null;

            if (Properties.Resources.IsWindowsMobileStandard)
            {
                items = ((ComboBox)lb).Items;
            }
            else
            {
                items = ((ListBox)lb).Items;
            }

            lb.SelectedIndex = items.Add(tb.Text);
        }
示例#35
0
 /// <summary>
 /// 下拉字典控件的绑定
 /// </summary>
 /// <param name="tab">控件关联数据源</param>
 /// <param name="ctrl">下拉控件</param>
 /// <param name="fld">控件关联字段</param>
 /// <param name="dictsrc">字典数据源</param>
 /// <param name="dicttxt">字典显示值</param>
 /// <param name="dictval">字典Value值</param>
 private void bindctrl(DataTable tab, ListControl ctrl, string fld, DataTable tabdict, string dicttxt, string dictval)
 {
     if (null == tab || null == ctrl || string.IsNullOrEmpty(fld))
         return;
     if (null == tabdict || (string.IsNullOrEmpty(dictval) && string.IsNullOrEmpty(dicttxt)))
     {
         ctrl.DataBindings.Add("Text", tab, fld);
         return;
     }
     ctrl.DataSource = tabdict;
     ctrl.ValueMember = string.IsNullOrEmpty(dictval) ? dicttxt : dictval;
     ctrl.DisplayMember = string.IsNullOrEmpty(dicttxt) ? dictval : dicttxt;
     ctrl.DataBindings.Add("SelectedValue", tab, fld);
 }
示例#36
0
 public ItemArray(ListControl listControl)
 {
     this.listControl = listControl;
 }
示例#37
0
 public ItemArray(ListControl listControl) {
     this.listControl = listControl;
 }
示例#38
0
        /// <summary>
        /// Gets the new index.
        /// </summary>
        /// <param name="lstControl">The list control instance.</param>
        /// <returns>The new index.</returns>
#if TargetF2
        public static int GetNewIndex(System.Windows.Forms.ListControl lstControl)
示例#39
0
 protected OptionsToolbarSection(ListControl listControl)
     : base(listControl)
 {
 }
示例#40
0
文件: Util.cs 项目: sim0629/negirc
 public static void removeItem(ListControl list, string text)
 {
     if (list == null) return;
     if (list.InvokeRequired)
         list.Invoke(new textHandler(uremoveItem), list, text);
     else uremoveItem(list, text);
 }
示例#41
0
 /// <summary>获取ListControl填充实体类</summary>
 /// <param name="entity"></param>
 /// <param name="field"></param>
 /// <param name="control"></param>
 private void GetListControl(IEntity entity, FieldItem field, ListControl control)
 {
     Object v = control.SelectedValue;
     if (v == null)
         v = control.Text;
     if (!Object.Equals(entity[field.Name], v)) SetEntityItem(entity, field, v);
 }
示例#42
0
        /// <summary>
        /// Sets the list item.
        /// </summary>
        /// <param name="lstControl">The list control instance.</param>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
#if TargetF2
        public static void SetListItem(System.Windows.Forms.ListControl lstControl, int index, string value)
示例#43
0
 private static IList ListControlItemsFor(ListControl listControl) {
     if (listControl is ListBox)
         return ((ListBox) listControl).Items;
     else if (listControl is CheckedListBox)
         return ((CheckedListBox) listControl).Items;
     else if (listControl is ComboBox)
         return ((ComboBox) listControl).Items;
     return null;
 }
示例#44
0
        /// <summary>
        /// Gets the list item.
        /// </summary>
        /// <param name="lstControl">The List control instance.</param>
        /// <param name="index">The index.</param>
        /// <returns>The list item.</returns>
#if TargetF2
        public static string GetListItem(System.Windows.Forms.ListControl lstControl, int index)
示例#45
0
 public GroupSection( ListControl listControl, RowIdentifier ri, HeaderSection headerSection, int position, int groupIndentWidth )
     : base(listControl, ri, headerSection, position)
 {
     Debug.Assert( ri is ListSection.GroupIdentifier );
     _groupIndentWidth = groupIndentWidth;
 }
示例#46
0
        /// <summary>
        /// Removes the item.
        /// </summary>
        /// <param name="lstControl">The list control instance.</param>
        /// <param name="index">The index.</param>
#if TargetF2
        public static void RemoveItem(System.Windows.Forms.ListControl lstControl, int index)