当前位置: 首页>>代码示例>>C#>>正文


C# ListBox.SetSelected方法代码示例

本文整理汇总了C#中System.Windows.Forms.ListBox.SetSelected方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.SetSelected方法的具体用法?C# ListBox.SetSelected怎么用?C# ListBox.SetSelected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ListBox的用法示例。


在下文中一共展示了ListBox.SetSelected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            // Create an instance of the ListBox.
            ListBox listBox1 = new ListBox();
            // Set the size and location of the ListBox.
            listBox1.Size = new System.Drawing.Size(200, 100);
            listBox1.Location = new System.Drawing.Point(10, 10);
            // Add the ListBox to the form.
            this.Controls.Add(listBox1);
            // Set the ListBox to display items in multiple columns.
            listBox1.MultiColumn = true;
            // Set the selection mode to multiple and extended.
            listBox1.SelectionMode = SelectionMode.MultiExtended;

            // Shutdown the painting of the ListBox as items are added.
            listBox1.BeginUpdate();
            // Loop through and add 50 items to the ListBox.
            for (int x = 1; x <= 50; x++)
            {
                listBox1.Items.Add("Item " + x.ToString());
            }
            // Allow the ListBox to repaint and display the new items.
            listBox1.EndUpdate();

            // Select three items from the ListBox.
            listBox1.SetSelected(1, true);
            listBox1.SetSelected(3, true);
            listBox1.SetSelected(5, true);

            // Display the second selected item in the ListBox to the console.
            System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems[1].ToString());
            // Display the index of the first selected item in the ListBox.
            System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices[0].ToString());
        }
开发者ID:klimskuridin,项目名称:vamk_csharp,代码行数:34,代码来源:Form1.cs

示例2: SelectAll

		private void SelectAll(ListBox listBox)
		{
			for (int i = 0; i < listBox.Items.Count; ++i)
			{
				listBox.SetSelected(i, true);
			}
		}
开发者ID:neemask,项目名称:meta-core,代码行数:7,代码来源:ExcelImportForm.cs

示例3: SetObjectTimeSlots

 public static void SetObjectTimeSlots(ListBox listBoxRoom, IEnumerable<TimeSlot> timeSlots)
 {
     listBoxRoom.ClearSelected();
     foreach (var timeSlot in timeSlots)
     {
         for (uint i = timeSlot.StartHour; i < timeSlot.EndHour; i++)
         {
             listBoxRoom.SetSelected((int)i - 7, true);
         }
     }
 }
开发者ID:victoria92,项目名称:university-program-generator,代码行数:11,代码来源:UIHelpers.cs

示例4: RemoveSelectedObjects

 public static void RemoveSelectedObjects(ListBox lst, ArrayList Arr = null)
 {
     if (lst == null) return;
     int MaxPos = 0;
     for (int k = 0; k < lst.Items.Count; k++)
     {
         if (lst.GetSelected(k))
         {
             MaxPos = k;
             lst.Items.RemoveAt(k);
             if (Arr != null)
                 Arr.RemoveAt(k);
             k--;
         }
     }
     if (lst.Items.Count > 0)
         if (MaxPos < lst.Items.Count)
             lst.SetSelected(MaxPos, true);
         else
             lst.SetSelected(lst.Items.Count - 1, true);
 }
开发者ID:Centronics,项目名称:FileUpdater,代码行数:21,代码来源:MainFrm.cs

示例5: CheckRepeatItem

 //检查item是否重复,重复返回true
 public static bool CheckRepeatItem(ListBox lb, object item)
 {
     for (int i = 0; i < lb.Items.Count; i++)
     {
         if (lb.Items[i].ToString().ToLower() == item.ToString().ToLower())
         {
             lb.SetSelected(i, true);  //重复选定Item
             return true;
         }
     }
     return false;
 }
开发者ID:KaminoDice,项目名称:Jovi-s-Software,代码行数:13,代码来源:BLL.cs

示例6: MoveItem

        public static void MoveItem(int direction, bool env, ListBox currentListBox, LoadedSettings loadedSettings)
        {
            // Checking selected item
            if (currentListBox.SelectedItem == null || currentListBox.SelectedIndex < 0)
                return; // No selected item - nothing to do

            // Calculate new index using move direction
            int newIndex = currentListBox.SelectedIndex + direction;

            // Checking bounds of the range
            if (newIndex < 0 || newIndex >= currentListBox.Items.Count)
                return; // Index out of range - nothing to do

            object selected = currentListBox.SelectedItem;

            // Removing removable element
            currentListBox.Items.Remove(selected);
            // Insert it in new position
            currentListBox.Items.Insert(newIndex, selected);
            // Restore selection
            currentListBox.SetSelected(newIndex, true);
            // Save changes
            SetCurrentOrderFromListBoxAndSave(env, currentListBox, loadedSettings);
        }
开发者ID:gr0ss,项目名称:RegistryMonitor,代码行数:24,代码来源:ListboxUtils.cs

示例7: InitializeComponents

		void InitializeComponents()
		{
			cmbForeColor = (ComboBox)ControlDictionary["cmbForeColor"];
			lstElements = (ListBox)ControlDictionary["lstElements"];
			cbBold = (CheckBox)ControlDictionary["cbBold"];
			cbItalic = (CheckBox)ControlDictionary["cbItalic"];
			cbUnderline = (CheckBox)ControlDictionary["cbUnderline"];
			lblOffsetPreview = (Label)ControlDictionary["lblOffsetPreview"];
			lblDataPreview = (Label)ControlDictionary["lblDataPreview"];
			btnSelectFont = (Button)ControlDictionary["btnSelectFont"];
			
			nUDBytesPerLine = (NumericUpDown)ControlDictionary["nUDBytesPerLine"];
			dUDViewModes = (DomainUpDown)ControlDictionary["dUDViewModes"];
			cbFitToWidth = (CheckBox)ControlDictionary["cbFitToWidth"];
			
			txtExtensions = (TextBox)ControlDictionary["txtExtensions"];
			
			fdSelectFont = new FontDialog();
			
			// Initialize FontDialog
			fdSelectFont.FontMustExist = true;
			fdSelectFont.FixedPitchOnly = true;
			fdSelectFont.ShowEffects = false;
			fdSelectFont.ShowColor = false;
			
			cmbForeColor.Items.Add(StringParser.Parse("${res:Global.FontStyle.CustomColor}"));
			
			foreach (Color c in Colors) {
				cmbForeColor.Items.Add(c.Name);
			}
			
			lstElements.Items.Add(StringParser.Parse("${res:AddIns.HexEditor.Display.Elements.Offset}"));
			lstElements.Items.Add(StringParser.Parse("${res:AddIns.HexEditor.Display.Elements.Data}"));

			lstElements.SetSelected(0, true);
			
			foreach (string s in HexEditor.Util.ViewMode.GetNames(typeof(HexEditor.Util.ViewMode)))
			{
				dUDViewModes.Items.Add(s);
			}
			
			btnSelectFont.Click += new EventHandler(this.btnSelectFontClick);
			cmbForeColor.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.cmbForeColorDrawItem);
			cmbForeColor.SelectedValueChanged += new EventHandler(this.cmbForeColorSelectedValueChanged);
			
			cmbForeColor.DropDown += cmbForeColorDropDown;
			
			cbBold.CheckedChanged += new EventHandler(this.cbBoldCheckedChanged);
			cbItalic.CheckedChanged += new EventHandler(this.cbItalicCheckedChanged);
			cbUnderline.CheckedChanged += new EventHandler(this.cbUnderlineCheckedChanged);
			
			lstElements.SelectedValueChanged += new EventHandler(this.lstElementsSelectedValueChanged);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:53,代码来源:HexEditOptionsPanel.cs

示例8: ChangeSelection

 private void ChangeSelection(ListBox listBox, bool selected)
 {
     for (int i = 0; i < listBox.Items.Count; i++)
     {
         listBox.SetSelected(i, selected);
     }
 }
开发者ID:igorskyx86,项目名称:SAP_HANA_VIEW_DUMPER,代码行数:7,代码来源:CalculationDumpDialog.cs

示例9: Add

        /// <summary>
        /// Add the selected items from the specified source <c>ListBox</c> control to the specified destination <c>ListBox</c> control.
        /// </summary>
        /// <param name="listSource">The source <c>ListBox</c> control.</param>
        /// <param name="listDestination">the destination <c>ListBox</c> control.</param>
        protected override void Add(ref ListBox listSource, ref ListBox listDestination)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            int count = listSource.SelectedItems.Count;
            int currentIndex = listSource.SelectedIndex;

            // Skip, if no items have been selected.
            if (count == 0)
            {
                return;
            }

            if ((m_ListItemCount + count) > Parameter.SizeTestList)
            {
                MessageBox.Show(Resources.MBTSelfTestsMaxExceeded, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Cursor = Cursors.WaitCursor;

            // ---------------------------------------------------------------------------------------
            // For each selected item: (a) add this to the destination list and update the added flag.
            // ---------------------------------------------------------------------------------------
            int selfTestIdentifier;
            for (int index = 0; index < count; ++index)
            {
                // Add the item to the destination list.
                listDestination.Items.Add(listSource.SelectedItems[index]);

                // Keep track of the number of tests that have been added to the test list.
                m_ListItemCount++;

                selfTestIdentifier = ((TestItem_t)listSource.SelectedItems[index]).SelfTestIdentifier;

                // Keep track of which watch variables have been removed.
                m_TestItems[selfTestIdentifier].Added = true;

                AddSupplementalFields(selfTestIdentifier);
            }

            UpdateCount();

            // Highlight the next item for processing if the list is not empty.
            if (listSource.Items.Count > 0)
            {
                // Bounds checking.
                if (currentIndex < listSource.Items.Count)
                {
                    listSource.SelectedIndex = currentIndex;
                }
                else if (currentIndex == listSource.Items.Count)
                {
                    listSource.SelectedIndex = currentIndex - 1;
                }
            }

            // Scroll to the end of the list.
            listDestination.SetSelected(listDestination.Items.Count - 1, true);
            listDestination.ClearSelected();

            m_ButtonApply.Enabled = true;
            OnDataUpdate(this, new EventArgs());
            Cursor = Cursors.Default;
        }
开发者ID:SiGenixDave,项目名称:PtuPCNew,代码行数:74,代码来源:FormTestListDefine.cs

示例10: SelectAllTagsInList

 private void SelectAllTagsInList(string tags, ListBox listBox)
 {
     string[] tagList = tags.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string tag in tagList)
     {
         for (int i = 0; i < listBox.Items.Count; i++)
         {
             if (tag.Equals(listBox.Items[i].ToString(), StringComparison.CurrentCultureIgnoreCase))
             {
                 listBox.SetSelected(i, true);
                 break;
             }
         }
     }
 }
开发者ID:dmarijanovic,项目名称:uber-tools,代码行数:15,代码来源:FormTagsEdit.cs

示例11: MoveListBoxItem

 private void MoveListBoxItem(ListBox list, int direction)
 {
     if (list.SelectedItem == null || list.SelectedIndex < 0) return;
     int index = list.SelectedIndex + direction;
     if (index < 0 || index >= list.Items.Count) return;
     object selected = list.SelectedItem;
     list.Items.Remove(selected);
     list.Items.Insert(index, selected);
     list.SetSelected(index, true);
 }
开发者ID:kib,项目名称:translations,代码行数:10,代码来源:frmPrefs.cs

示例12: autoSearch

        private void autoSearch(ListBox l, string s)
        {
            for (int x = 0; x <= l.Items.Count - 1; x++)
            {

                int firstCharacter = l.Items[x].ToString().IndexOf(s);
                if (firstCharacter != -1 && s != "")
                {
                    l.SetSelected(x, true);
                    l.TopIndex = x; //firstCharacter;
                    break;

                }
                else
                    l.SetSelected(0, false);
            }
        }
开发者ID:AugustusMN,项目名称:Dashboard,代码行数:17,代码来源:appUnit.cs

示例13: SelectAll

 public static void SelectAll(ListBox p0)
 {
     for (int i = 0; i < p0.Items.Count; i++){
         p0.SetSelected(i, true);
     }
 }
开发者ID:neuhauser,项目名称:compbio-base,代码行数:6,代码来源:MultiListSelector.cs

示例14: getPlaces

 public void getPlaces(ListBox placesListBox, Label messageLabel, string keyword)
 {
     try
     {
         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(m_url + "?intext=" + keyword);
         req.KeepAlive = false;
         WebResponse res = req.GetResponse();
         Stream responseStream = res.GetResponseStream();
         StreamReader reader = new StreamReader (responseStream);
         citiesList.Clear();
         list.Clear();
         string line;
         while((line=reader.ReadLine()) != null)
         {
             //LibSys.StatusBar.Trace(line);
             City city=parseCityString(line);
             if(city != null)
             {
                 citiesList.Add(city);
                 list.Add(city.toTableString());
                 //LibSys.StatusBar.Trace(city.toTableString());
                 placesListBox.Items.Add(city.toTableString());
             }
         }
         responseStream.Close();
         if(list.Count > 0)
         {
             placesListBox.SetSelected(0, true);
             messageLabel.Text = "select city from the list below and click this button -------->";
         }
         else
         {
             messageLabel.Text = "no cities or US zipcode matched keyword '" + Project.findKeyword + "'";
         }
     }
     catch (Exception e)
     {
         messageLabel.Text = "" + e.Message;
         //LibSys.StatusBar.Error("ZipcodeServer() - " + e);
     }
 }
开发者ID:slgrobotics,项目名称:QuakeMap,代码行数:41,代码来源:ZipcodeServer.cs

示例15: moveSelectedField

        public static void moveSelectedField(ListBox listBoxSelected, bool bUp)
        {
            if (listBoxSelected == null)
            return;

             int nFirstSelndex = -1;
             int nSelCount = 0;
             if (bUp) //move up
             {
            nFirstSelndex = listBoxSelected.SelectedIndices[0];
            nSelCount = listBoxSelected.SelectedIndices.Count;
            string str = listBoxSelected.Items[nFirstSelndex - 1].ToString();
            listBoxSelected.Items.RemoveAt(nFirstSelndex - 1);
            listBoxSelected.Items.Insert(nFirstSelndex + nSelCount - 1, str);

            nFirstSelndex = nFirstSelndex - 1;
             }
             else //move down
             {
            nFirstSelndex = listBoxSelected.SelectedIndices[0];
            nSelCount = listBoxSelected.SelectedIndices.Count;
            int nLastSelIndex = nFirstSelndex + nSelCount - 1;

            string str = listBoxSelected.Items[nLastSelIndex + 1].ToString();
            listBoxSelected.Items.RemoveAt(nLastSelIndex + 1);
            listBoxSelected.Items.Insert(nFirstSelndex, str);

            nFirstSelndex = nFirstSelndex + 1;
             }

             listBoxSelected.SelectedItems.Clear();
             for (int ii = 0; ii < nSelCount; ++ii)
             {
            listBoxSelected.SetSelected(nFirstSelndex + ii, true);
             }
        }
开发者ID:jeremytammik,项目名称:UserMepCalculation,代码行数:36,代码来源:ReportSettings.cs


注:本文中的System.Windows.Forms.ListBox.SetSelected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。