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


C# ListView.Focus方法代码示例

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


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

示例1: SelectProject

 private static void SelectProject(ListView lstSelectProject, string ProjectName)
 {
     int num = FindBestProject(lstSelectProject, ProjectName);
     lstSelectProject.Focus();
     lstSelectProject.SelectedItems[0].Selected = false;
     lstSelectProject.Items[num].Selected = true;
     lstSelectProject.SelectedItems[0].EnsureVisible();
 }
开发者ID:x893,项目名称:WDS,代码行数:8,代码来源:ProjectDataSerializer.cs

示例2: SaveParameters

 private bool SaveParameters(ListView parameterListView, IDictionary<string, string> parameterList)
 {
     parameterList.Clear();
     List<string> names = new List<string>();
     foreach (ListViewItem lvi in parameterListView.Items)
     {
         // some sanity checking on the parameter names
         string param = lvi.SubItems[0].Text;
         string name = new Regex("[^a-z0-9_]").Replace(param, "");
         if (name == "" || new Regex("[0-9]").IsMatch(name.Substring(0, 1)))
         {
             MessageBox.Show(string.Format("{0} is not a valid parameter name", param), TemplateName);
             parameterListView.Focus();
             parameterListView.SelectedItems.Clear();
             lvi.Selected = true;
             DialogResult = DialogResult.None;
             return false;
         }
         if (names.Contains(name))
         {
             MessageBox.Show(string.Format("{0}: duplicated parameter", name), TemplateName);
             parameterListView.Focus();
             parameterListView.SelectedItems.Clear();
             lvi.Selected = true;
             DialogResult = DialogResult.None;
             return false;
         }
         names.Add(name);
         parameterList.Add(lvi.SubItems[0].Text, lvi.SubItems[1].Text);
     }
     return true;
 }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:32,代码来源:TemplatorConfig.cs

示例3: MoveListViewItems

        private static void MoveListViewItems(ListView listView, MoveDirection direction)
        {
            var valid = listView.SelectedItems.Count > 0 &&
                        ((direction == MoveDirection.Down &&
                          (listView.SelectedItems[listView.SelectedItems.Count - 1].Index < listView.Items.Count - 1))
                         || (direction == MoveDirection.Up && (listView.SelectedItems[0].Index > 0)));

            if (!valid)
                return;

            var start = true;
            var firstIdx = 0;
            var items = new List<ListViewItem>();

            foreach (ListViewItem i in listView.SelectedItems)
            {
                if (start)
                {
                    firstIdx = i.Index;
                    start = false;
                }
                items.Add(i);
            }

            listView.BeginUpdate();

            foreach (ListViewItem i in listView.SelectedItems)
            {
                i.Remove();
            }

            if (direction == MoveDirection.Up)
            {
                var insertTo = firstIdx - 1;
                foreach (var i in items)
                {
                    i.Selected = true;
                    listView.Items.Insert(insertTo, i);
                    insertTo++;
                }
            }
            else
            {
                var insertTo = firstIdx + 1;
                foreach (var i in items)
                {
                    i.Selected = true;
                    listView.Items.Insert(insertTo, i);
                    insertTo++;
                }
            }

            listView.EndUpdate();
            listView.Focus();
        }
开发者ID:Xuno,项目名称:MPDN_Extensions,代码行数:55,代码来源:RenderChainList.cs

示例4: SelectedListViewItemDown

        public static void SelectedListViewItemDown(ListView aListView)
        {
            if (aListView.SelectedItems.Count > 0)
            {
                aListView.BeginUpdate();
                int indexMaxSelectedItem = aListView.SelectedItems[aListView.SelectedItems.Count - 1].Index;

                if (indexMaxSelectedItem < aListView.Items.Count - 1)
                {
                    for (int i = aListView.SelectedItems.Count - 1; i >= 0; i--)
                    {
                        ListViewItem lviSelectedItem = aListView.SelectedItems[i];
                        int indexSelectedItem = lviSelectedItem.Index;
                        aListView.Items.RemoveAt(indexSelectedItem);
                        aListView.Items.Insert(indexSelectedItem + 1, lviSelectedItem);
                    }
                }
                aListView.EndUpdate();

                aListView.Focus();
                aListView.SelectedItems[aListView.SelectedItems.Count - 1].Focused = true;
                aListView.SelectedItems[aListView.SelectedItems.Count - 1].EnsureVisible();
            }
        }
开发者ID:san90279,项目名称:UK_OAS,代码行数:24,代码来源:WzdUtils.cs

示例5: SelectedListViewItemUp

        public static void SelectedListViewItemUp(ListView aListView)
        {
            if (aListView.SelectedItems.Count > 0)
            {
                aListView.BeginUpdate();
                if (aListView.SelectedItems[0].Index > 0)
                {
                    foreach (ListViewItem lvi in aListView.SelectedItems)
                    {
                        ListViewItem lviSelectedItem = lvi;
                        int indexSelectedItem = lvi.Index;
                        aListView.Items.RemoveAt(indexSelectedItem);
                        aListView.Items.Insert(indexSelectedItem - 1, lviSelectedItem);
                    }
                }
                aListView.EndUpdate();

                aListView.Focus();
                aListView.SelectedItems[0].Focused = true;
                aListView.SelectedItems[0].EnsureVisible();
            }
        }
开发者ID:san90279,项目名称:UK_OAS,代码行数:22,代码来源:WzdUtils.cs

示例6: searchList

 /// <summary>
 /// General function to search any list view form. Highlights rows with matches.
 /// </summary>
 /// <param name="needle">String to search for</param>
 /// <param name="haystack">ListView object to search in</param>
 private void searchList(string needle, ListView haystack)
 {
     if (haystack.Items.Count > 0)
     {
         // Focus the list view
         haystack.Focus();
         // Clear currently selected items
         haystack.SelectedItems.Clear();
         int i = 0;
         ListViewItem found;
         do
         {
             // Recursively find all instances of the given text, starting from zero
             found = haystack.FindItemWithText(needle, true, i, true);
             if (found != null)
             {
                 // Select found item
                 found.Selected = true;
                 // Next search starts from the next element in the list view
                 i = found.Index + 1;
             }
             else
             {
                 // Otherwise, stop
                 i = haystack.Items.Count;
             }
         } while (i < haystack.Items.Count);
     }
     // If nothing found, show message
     if (haystack.SelectedItems.Count == 0)
     {
         MessageBox.Show("Value could not be found.", "Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
开发者ID:CJxD,项目名称:CoreView,代码行数:39,代码来源:MainWindowSearching.cs

示例7: ReforcusListView

        /// <summary>
        /// リストビューのフォーカスをリセットします。
        /// </summary>
        /// <param name="listView">対象のリストビュー</param>
        private void ReforcusListView(ListView listView)
        {
            // ListViewItemSorterを解除する
            listView.ListViewItemSorter = null;

            // ツリービューとリストビューの表示を更新する
            UpdateTreeView();
            UpdateListView();

            // ListViewItemSorterを指定する
            listView1.ListViewItemSorter = listViewItemSorter;

            // フォーカスを当て直す
            listView.Items[currentRow].Selected = true;
            listView.SelectedItems[0].EnsureVisible();
            listView.Select();
            listView.Focus();
        }
开发者ID:kinokino2010,项目名称:AkaneMail,代码行数:22,代码来源:MainForm.cs

示例8: ListViewUpMove

 // 上移
 private void ListViewUpMove(ListView listView)
 {
     if (listView.SelectedItems.Count == 0)
     {
         return;
     }
     listView.BeginUpdate();
     if (listView.SelectedItems[0].Index > 0)
     {
         foreach (ListViewItem lvi in listView.SelectedItems)
         {
             ListViewItem lviSelectedItem = lvi;
             int indexSelectedItem = lvi.Index;
             listView.Items.RemoveAt(indexSelectedItem);
             listView.Items.Insert(indexSelectedItem - 1, lviSelectedItem);
         }
     }
     listView.EndUpdate();
     if (listView.Items.Count > 0 && listView.SelectedItems.Count > 0)
     {
         listView.Focus();
         listView.SelectedItems[0].Focused = true;
         listView.SelectedItems[0].EnsureVisible();
     }
 }
开发者ID:ShongSu,项目名称:StudentManager,代码行数:26,代码来源:frmSelectedColumn.cs

示例9: ListViewDownMove

 //下移
 private void ListViewDownMove(ListView listView)
 {
     if (listView.SelectedItems.Count == 0)
     {
         return;
     }
     listView.BeginUpdate();
     int indexMaxSelectedItem = listView.SelectedItems[listView.SelectedItems.Count - 1].Index;
     if (indexMaxSelectedItem < listView.Items.Count - 1)
     {
         for (int i = listView.SelectedItems.Count - 1; i >= 0; i--)
         {
             ListViewItem lviSelectedItem = listView.SelectedItems[i];
             int indexSelectedItem = lviSelectedItem.Index;
             listView.Items.RemoveAt(indexSelectedItem);
             listView.Items.Insert(indexSelectedItem + 1, lviSelectedItem);
         }
     }
     listView.EndUpdate();
     if (listView.Items.Count > 0 && listView.SelectedItems.Count > 0)
     {
         listView.Focus();
         listView.SelectedItems[listView.SelectedItems.Count - 1].Focused = true;
         listView.SelectedItems[listView.SelectedItems.Count - 1].EnsureVisible();
     }
 }
开发者ID:ShongSu,项目名称:StudentManager,代码行数:27,代码来源:frmSelectedColumn.cs

示例10: Bug468271Test

		public void Bug468271Test ()
		{
			// NOTE: This test only exposes bug in Provider side.
			// ListView_details: "table cell" isn't accessible without "focused"
			ListView listview = new ListView ();
			listview.View = View.Details;
			listview.CheckBoxes = true;
			listview.GridLines = true;
			listview.Sorting = SortOrder.Ascending;
			listview.Dock = DockStyle.Top;
			listview.Width = 350;
			listview.Height = 260;

			listview.Columns.Add ("Column1", 200, HorizontalAlignment.Left);
			listview.Columns.Add ("Column2", 200, HorizontalAlignment.Left);
			listview.Columns.Add ("Column3", 200, HorizontalAlignment.Left);

			for (int index = 0; index < 3; index++) {
				ListViewItem item = new ListViewItem (string.Format ("Item:{0}", index));
				item.SubItems.Add (index.ToString ());
				item.SubItems.Add ((index+10).ToString ());
				listview.Items.Add (item);
			}

			// We have the following table:
			// "Column1"         | "Column2" | "Column3"
			// ------------------|-----------|----------
			// checkbox, "Item0" | "0"       | "10"
			// checkbox, "Item1" | "1"       | "11"
			// checkbox, "Item2" | "2"       | "12"

			// ListViewUIATree:
			// - Header
			//   - HeaderItem "Column1"
			//   - HeaderItem "Column2"
			//   - HeaderItem "Column3"
			// - DataItem "Item0"
			//   - CheckBox
			//   - "Item0"
			//   - "0"
			//   - "10"
			// - DataItem "Item1"
			//   - CheckBox
			//   - "Item1"
			//   - "1"
			//   - "11"
			// - DataItem "Item2"
			//   - CheckBox
			//   - "Item2"
			//   - "2"
			//   - "12"
			IRawElementProviderFragmentRoot root
				= (IRawElementProviderFragmentRoot) GetProviderFromControl (listview);
			Assert.IsNotNull (root, "Missing ListViewProvider");
			IRawElementProviderFragmentRoot []dataItems = new IRawElementProviderFragmentRoot [3];
			IRawElementProviderFragment child = root.Navigate (NavigateDirection.FirstChild);
			Assert.IsNotNull (child, "Missing child");
			
			int dataItem = 0;
			while (child != null) {				
				if ((int) child.GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id)
				    == ControlType.DataItem.Id) {
					dataItems [dataItem] = (IRawElementProviderFragmentRoot) child;
					dataItem++;
				}
				child = child.Navigate (NavigateDirection.NextSibling);
			}
			Assert.AreEqual (dataItems.Length, dataItem, "Count != DataItems");

			// You *can* only focus 1 item, so, focusing a different item
			// will unfocus previous item and focus new item.

			// listview.FullRowSelect = false: first subitem will is selected.
			bridge.ResetEventLists ();
			listview.Focus ();
			listview.Items [0].Focused = true;
			TestFocusInDataItemChildren (listview, 0, dataItems [0], true);

			bridge.ResetEventLists ();
			listview.Items [1].Focused = true;
			TestFocusInDataItemChildren (listview, 1, dataItems [1], true);
			TestFocusInDataItemChildren (listview, 0, dataItems [0], false);

			bridge.ResetEventLists ();
			listview.Items [2].Focused = true;
			TestFocusInDataItemChildren (listview, 2, dataItems [2], true);			
			TestFocusInDataItemChildren (listview, 1, dataItems [1], false);
		}
开发者ID:mono,项目名称:uia2atk,代码行数:88,代码来源:ListViewProviderTest.cs

示例11: MoveListViewItem

        //Pulled from http://www.knowdotnet.com/articles/listviewmoveitem.html
        private void MoveListViewItem(ref ListView lv, bool moveUp)
        {
            string cache;
            int selIdx;
            bool itemchecked = false;
            bool otheritemchecked = false;

            selIdx = lv.SelectedItems[0].Index;
            if (lv.Items[selIdx].Checked) { itemchecked = true; }
            if (moveUp)
            {
                if (lv.Items[selIdx - 1].Checked) { otheritemchecked = true; }
                // ignore moveup of row(0)
                if (selIdx == 0)
                    return;

                // move the subitems for the previous row
                // to cache to make room for the selected row
                for (int i = 0; i < lv.Items[selIdx].SubItems.Count; i++)
                {
                    cache = lv.Items[selIdx - 1].SubItems[i].Text;
                    lv.Items[selIdx - 1].SubItems[i].Text =
                      lv.Items[selIdx].SubItems[i].Text;
                    lv.Items[selIdx].SubItems[i].Text = cache;
                }
                lv.Items[selIdx - 1].Selected = true;
                if (itemchecked) { lv.Items[selIdx - 1].Checked = true; } else { lv.Items[selIdx - 1].Checked = false; }
                if (otheritemchecked)
                {
                    lv.Items[selIdx].Checked = true;
                }
                else
                {
                    lv.Items[selIdx].Checked = false;
                }
                lv.Refresh();
                lv.Focus();
            }
            else
            {
                if (lv.Items[selIdx + 1].Checked) { otheritemchecked = true; }
                // ignore movedown of last item
                if (selIdx == lv.Items.Count - 1)
                    return;
                // move the subitems for the next row
                // to cache so we can move the selected row down
                for (int i = 0; i < lv.Items[selIdx].SubItems.Count; i++)
                {
                    cache = lv.Items[selIdx + 1].SubItems[i].Text;
                    lv.Items[selIdx + 1].SubItems[i].Text =
                      lv.Items[selIdx].SubItems[i].Text;
                    lv.Items[selIdx].SubItems[i].Text = cache;
                }
                lv.Items[selIdx + 1].Selected = true;
                if (itemchecked) { lv.Items[selIdx + 1].Checked = true; } else { lv.Items[selIdx + 1].Checked = false; }
                if (otheritemchecked)
                {
                    lv.Items[selIdx].Checked = true;
                }
                else
                {
                    lv.Items[selIdx].Checked = false;
                }
                lv.Refresh();
                lv.Focus();
            }
        }
开发者ID:jesusspork,项目名称:Xenix,代码行数:68,代码来源:AccountForm.cs

示例12: AddDataGridViewToTabControl

        /// <summary>
        /// Lägger till en DataGridView i TabControlern
        /// </summary>
        /// <param name="tabControl1"></param>
        /// <param name="listViewDivers"></param>
        /// <param name="_diveNo"></param>
        /// <param name="_diveName"></param>
        /// <param name="_dataGridViewList"></param>
        /// <param name="DiveCount_numericUpDown"></param>
        /// <param name="panel1"></param>
        public static void AddDataGridViewToTabControl(TabControl tabControl1, ListView listViewDivers, AutoCompleteStringCollection _diveNo, AutoCompleteStringCollection _diveName, List<DataGridView> _dataGridViewList, NumericUpDown DiveCount_numericUpDown, Panel panel1)
        {
            string[] row = new string[] { "A", "1", "Dummy Dive"};
            tabControl1.TabPages.Clear();

            if (listViewDivers.CheckedItems.Count > 0)
            {
                panel1.Visible = true;
                tabControl1.Visible = true;
                //antal tabbar
                for (int i = 0; i < listViewDivers.CheckedItems.Count; i++)
                {
                    //om det har lagts till en ny hoppare skapas en ny DataGridView
                    if(listViewDivers.CheckedItems.Count > _dataGridViewList.Count)
                    {
                        DataGridView newDataGrid = NewEventPresenter.GetNewDataGridView(_diveNo, _diveName, tabControl1);
                        newDataGrid.Dock = DockStyle.Fill;
                        _dataGridViewList.Add(newDataGrid);
                    }

                    _dataGridViewList[i].Columns[2].Width = tabControl1.Width - (51 + 55 + 55);

                    //DataGridViewens tag är den samma som Diverns ID
                    _dataGridViewList[i].Tag = listViewDivers.CheckedItems[i].SubItems[4].Text;

                    //antal rader
                    if (_dataGridViewList[i].RowCount <= Int32.Parse(DiveCount_numericUpDown.Value.ToString())) //om det är mindre rader än NumericUpDown
                    {
                        for (int j = _dataGridViewList[i].RowCount; j < Int32.Parse(DiveCount_numericUpDown.Value.ToString()); j++)
                        {
                            _dataGridViewList[i].Rows.Add(row);
                            _dataGridViewList[i].Rows[j].HeaderCell.Value = String.Format("{0}", j + 1);
                        }
                    }
                    else if (_dataGridViewList[i].RowCount > Int32.Parse(DiveCount_numericUpDown.Value.ToString())) //om det är fler rader än NumericUpDown
                    {
                        for (int j = _dataGridViewList[i].RowCount; j > Int32.Parse(DiveCount_numericUpDown.Value.ToString()); j--)
                        {
                            _dataGridViewList[i].Rows.Remove(_dataGridViewList[i].Rows[j - 1]);
                        }
                    }

                    _dataGridViewList[i].Visible = true;
                    string title = listViewDivers.CheckedItems[i].Text;
                    TabPage newTab = new TabPage(title);
                    newTab.Name = i.ToString();
                    newTab.Tag = listViewDivers.CheckedItems[i].SubItems[4].Text;

                    tabControl1.TabPages.Add(newTab);
                    newTab.Controls.Add(_dataGridViewList[i]);
                    listViewDivers.Focus();
                }
            }
            else
            {
                panel1.Visible = false;
                tabControl1.Visible = false;
            }
        }
开发者ID:uvRen,项目名称:teamb-simhopp,代码行数:69,代码来源:NewEventPresenter.cs


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