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


C# ListViewItem.GetLength方法代码示例

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


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

示例1: OnDragDrop

        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            //Return if the items are not selected in the ListView control.
            if (this.SelectedItems.Count == 0)
            {
                return;
            }
            //Returns the location of the mouse pointer in the ListView control.
            Point cp = this.PointToClient(new Point(drgevent.X, drgevent.Y));
            //Obtain the item that is located at the specified location of the mouse pointer.
            ListViewItem dragToItem = this.GetItemAt(cp.X, cp.Y);
            if (dragToItem == null)
            {
                return;
            }
            //Obtain the index of the item at the mouse pointer.
            int dragIndex = dragToItem.Index;
            ListViewItem[] sel = new ListViewItem[this.SelectedItems.Count];
            for (int i = 0; i <= this.SelectedItems.Count - 1; i++)
            {
                sel[i] = this.SelectedItems[i];
            }
            for (int i = 0; i < sel.GetLength(0); i++)
            {
                //Obtain the ListViewItem to be dragged to the target location.
                ListViewItem dragItem = sel[i];
                int itemIndex = dragIndex;
                if (itemIndex == dragItem.Index)
                {
                    return;
                }
                if (dragItem.Index < itemIndex)
                    itemIndex++;
                else
                    itemIndex = dragIndex + i;
                //Insert the item at the mouse pointer.
                ListViewItem insertItem = (ListViewItem)dragItem.Clone();
                this.Items.Insert(itemIndex, insertItem);
                //Removes the item from the initial location while 
                //the item is moved to the new location.
                this.Items.Remove(dragItem);
            }

            base.OnDragDrop(drgevent);
        }
开发者ID:memerdot,项目名称:puyotools-1,代码行数:45,代码来源:ListViewWithReordering.cs

示例2: scanListView_DragDrop

        private void scanListView_DragDrop(object sender, DragEventArgs e)
        {
            if (scanListView.SelectedItems.Count == 0)
            {
                return;
            }

            Point cp = scanListView.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = scanListView.GetItemAt(cp.X, cp.Y);

            if (dragToItem == null)
            {
                return;
            }

            int dragIndex = dragToItem.Index;

            ListViewItem[] sel = new ListViewItem[scanListView.SelectedItems.Count];
            MainScanItem[] vsel = new MainScanItem[scanListView.SelectedItems.Count];

            for (int i = 0; i < scanListView.SelectedItems.Count; i++)
            {
                sel[i] = scanListView.SelectedItems[i];
                vsel[i] = scanItems[scanListView.SelectedIndices[i]];
            }

            for (int i = 0; i < sel.GetLength(0); i++)
            {
                ListViewItem dragItem = sel[i];
                MainScanItem vdragItem = vsel[i];

                int itemIndex = dragIndex;

                if (itemIndex == dragItem.Index)
                {
                    return;
                }

                bool isStart = false;
                if (vdragItem.Steam.scaninProg)
                {
                    vdragItem.Steam.CancelScan();
                    isStart = true;
                }

                if (dragItem.Index < itemIndex)
                    itemIndex++;
                else
                    itemIndex = dragIndex + i;

                MainScanItem insertVItem = new MainScanItem(new saveTab(vdragItem.Steam.scanInput), steam_srch.cookieCont, new eventDelegate(Event_Message), settings.ignoreWarn, settings.resellDelay);
                insertVItem.LogCont = vdragItem.LogCont;

                if (isStart)
                {
                    insertVItem.Steam.ScanPrices();
                }

                scanItems.Insert(itemIndex, insertVItem);
                scanItems.Remove(vdragItem);
                scanItems.UpdateIds();

                ListViewItem insertItem = (ListViewItem)dragItem.Clone();
                scanListView.Items.Insert(itemIndex, insertItem);
                scanListView.Items.Remove(dragItem);
                insertItem.Selected = true;
            }
        }
开发者ID:jmazzola,项目名称:SCMBot,代码行数:68,代码来源:Main.cs

示例3: recentListView_DragDrop

        private void recentListView_DragDrop(object sender, DragEventArgs e)
        {
            if (recentListView.SelectedItems.Count == 0)
            {
                return;
            }

            Point cp = recentListView.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = recentListView.GetItemAt(cp.X, cp.Y);

            if (dragToItem == null)
            {
                return;
            }

            int dragIndex = dragToItem.Index;

            ListViewItem[] sel = new ListViewItem[recentListView.SelectedItems.Count];
            saveTab[] vsel = new saveTab[recentListView.SelectedItems.Count];

            for (int i = 0; i < recentListView.SelectedItems.Count; i++)
            {
                sel[i] = recentListView.SelectedItems[i];
                vsel[i] = steam_srch.recentInputList[recentListView.SelectedIndices[i]];
            }

            for (int i = 0; i < sel.GetLength(0); i++)
            {
                ListViewItem dragItem = sel[i];
                saveTab vdragItem = vsel[i];

                int itemIndex = dragIndex;

                if (itemIndex == dragItem.Index)
                {
                    return;
                }

                if (dragItem.Index < itemIndex)
                    itemIndex++;
                else
                    itemIndex = dragIndex + i;

                saveTab insertVItem = new saveTab(vdragItem);

                steam_srch.recentInputList.Insert(itemIndex, insertVItem);
                steam_srch.recentInputList.Remove(vdragItem);

                ListViewItem insertItem = (ListViewItem)dragItem.Clone();
                recentListView.Items.Insert(itemIndex, insertItem);
                recentListView.Items.Remove(dragItem);
                insertItem.Selected = true;
            }
        }
开发者ID:jmazzola,项目名称:SCMBot,代码行数:54,代码来源:Main.cs

示例4: listView_DragDrop

        /// <summary>
        /// 放下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView_DragDrop(object sender, DragEventArgs e)
        {
            ListView lv = (ListView)(sender);

            string src = "";
            string dest = "";

            statusLabel.Text = "拖动结束,开始移动。";
            //判断是否选择拖放的项,

            //选择拖动数为0
            if (lv.SelectedItems.Count == 0)
            {
                return;
            }
            else if (lv.SelectedItems.Count != 1)
            {
                statusLabel.Text = "拖动图片时只能选择一张图片。";
                return;
            }

            //定义项的坐标点并获取目的item
            Point cp = lv.PointToClient(new Point(e.X, e.Y));
            ListViewItem destItem = lv.GetItemAt(cp.X, cp.Y);
            if (destItem == null)
            {
                statusLabel.Text = "拖动目的位置坐标必须在item上,表示移动到该item之前";
                return;
            }
            int destIndex = destItem.Index;

            dest = destItem.Text;

            //不需要移动
            if (destIndex == lv.SelectedItems[0].Index)
            {
                return;
            }

            int appCount = 0;
            //获取需要拖动的item
            ListViewItem selItem = (ListViewItem)lv.SelectedItems[0].Clone();
            src = selItem.Text;
            if (lv.SelectedItems[0].Index < destIndex)
            {
                appCount = lv.Items.Count - destIndex;
                destIndex--;
            }
            else
            {
                appCount = lv.Items.Count - destIndex - 1;
            }
            lv.Items.Remove(lv.SelectedItems[0]);

            //所有最后需附加的item
            ListViewItem[] appendItems = new ListViewItem[appCount];
            for (int i = destIndex; destIndex < lv.Items.Count; i++)
            {
                appendItems[i - destIndex] = (ListViewItem)lv.Items[destIndex].Clone();
                lv.Items.RemoveAt(destIndex);
            }

            lv.Items.Insert(destIndex++, selItem);
            for (int i = 0; i < appendItems.GetLength(0); i++)
            {
                lv.Items.Insert(destIndex++, appendItems[i]);
            }

            statusLabel.Text = "移动    " + src + "   至   " + dest + "    之前。";
        }
开发者ID:holenzh,项目名称:CSharpProjAtYC,代码行数:75,代码来源:SelImageForm.cs

示例5: modView_DragDrop

        private void modView_DragDrop(object sender, DragEventArgs e)
        {
            int dragIndex = modView.InsertionMark.Index +
                (modView.InsertionMark.AppearsAfterItem ? 1 : 0);
            if (modView.Items.Count <= 0)
                dragIndex = 0;

            if (e.Data.GetDataPresent(
                "System.Windows.Forms.ListView+SelectedListViewItemCollection") &&
                dragIndex >= 0)
            {
                // Return if the items are not selected in the ListView control.
                if (modView.SelectedItems.Count == 0)
                {
                    return;
                }

                // Returns the location of the mouse pointer in the ListView control.
                Point cp = modView.PointToClient(new Point(e.X, e.Y));

                //if (modView.InsertionMark.AppearsAfterItem)
                //    dragIndex++;
                ListViewItem[] sel = new ListViewItem[modView.SelectedItems.Count];
                for (int i = 0; i <= modView.SelectedItems.Count - 1; i++)
                {
                    sel[i] = modView.SelectedItems[i];
                }
                for (int i = 0; i < sel.GetLength(0); i++)
                {
                    // Obtain the ListViewItem to be dragged to the target location.
                    ListViewItem dragItem = sel[i];
                    int itemIndex = dragIndex;
                    if (itemIndex == dragItem.Index)
                    {
                        return;
                    }
                    //if (dragItem.Index < itemIndex)
                    //    itemIndex++;
                    //else
                    //    itemIndex = dragIndex + i;

                    // Insert the item at the mouse pointer.
                    ListViewItem insertItem = (ListViewItem)dragItem.Clone();

                    if (itemIndex >= modView.Items.Count)
                        itemIndex = modView.Items.Count;

                    modView.Items.Insert(itemIndex, insertItem);

                    // Removes the item from the initial location while
                    // the item is moved to the new location.
                    modView.Items.Remove(dragItem);
                }

                SaveModList();
            }
            else if (e.Data.GetDataPresent("FileDrop"))
            {
                string[] files = (string[])e.Data.GetData("FileDrop");
                e.Effect = DragDropEffects.Copy;
                AddMods(files, dragIndex);
            }
            else
            {
                e.Effect = DragDropEffects.None;
                modView.InsertionMark.Index = -1;
            }
        }
开发者ID:Tom-V,项目名称:MultiMC,代码行数:68,代码来源:EditModsForm.cs

示例6: listViewPlaybackSequence_DragDrop

 /// <summary>
 /// Handles the DragDrop event of the listViewPlaybackSequence control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
 /// <remarks>Documented by Dev02, 2008-03-29</remarks>
 private void listViewPlaybackSequence_DragDrop(object sender, DragEventArgs e)
 {
     //Return if the items are not selected in the ListView control.
     if (listViewPlaybackSequence.SelectedItems.Count == 0)
     {
         return;
     }
     //Returns the location of the mouse pointer in the ListView control.
     Point cp = listViewPlaybackSequence.PointToClient(new Point(e.X, e.Y));
     //Obtain the item that is located at the specified location of the mouse pointer.
     ListViewItem dragToItem = listViewPlaybackSequence.GetItemAt(cp.X, cp.Y);
     if (dragToItem == null)
     {
         return;
     }
     //Obtain the index of the item at the mouse pointer.
     int dragIndex = dragToItem.Index;
     ListViewItem[] sel = new ListViewItem[listViewPlaybackSequence.SelectedItems.Count];
     for (int i = 0; i <= listViewPlaybackSequence.SelectedItems.Count - 1; i++)
     {
         sel[i] = listViewPlaybackSequence.SelectedItems[i];
     }
     for (int i = 0; i < sel.GetLength(0); i++)
     {
         //Obtain the ListViewItem to be dragged to the target location.
         ListViewItem dragItem = sel[i];
         int itemIndex = dragIndex;
         if (itemIndex == dragItem.Index)
         {
             return;
         }
         if (dragItem.Index < itemIndex)
             itemIndex++;
         else
             itemIndex = dragIndex + i;
         //Insert the item at the mouse pointer.
         ListViewItem insertItem = (ListViewItem)dragItem.Clone();
         listViewPlaybackSequence.Items.Insert(itemIndex, insertItem);
         //Removes the item from the initial location while
         //the item is moved to the new location.
         listViewPlaybackSequence.Items.Remove(dragItem);
     }
 }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:49,代码来源:MainForm.cs

示例7: lvPlays_DragDrop

        private void lvPlays_DragDrop(object sender, DragEventArgs e)
        {
            // Return if the items are not selected in the ListView control.
            if (lvAvailable.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem[] sel = new ListViewItem[lvAvailable.SelectedItems.Count];
            for (int i = 0; i <= lvAvailable.SelectedItems.Count - 1; i++)
            {
                sel[i] = lvAvailable.SelectedItems[i];
            }
            for (int i = 0; i < sel.GetLength(0); i++)
            {
                // Obtain the ListViewItem to be dragged to the target location.
                ListViewItem dragItem = sel[i];
                ListViewItem insertItem = (ListViewItem)dragItem.Clone();
                lvPlays.Items.Add(insertItem);

                // Removes the item from the initial location while
                // the item is moved to the new location.
                lvAvailable.Items.Remove(dragItem);
            }
        }
开发者ID:uwcbc,项目名称:uwcbc-marimba,代码行数:24,代码来源:editMultiInstruments.cs

示例8: OnDragDrop

        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            base.OnDragDrop(drgevent);

              if (!DragAndDropEnabled)
            return;

              if (SelectedItems.Count == 0)
            return;

              var cp = PointToClient(new Point(drgevent.X, drgevent.Y));

              var dragToItem = GetItemAt(cp.X, cp.Y);
              if (dragToItem == null)
            return;

              int dragIndex = dragToItem.Index;

              ListViewItem[] sel = new ListViewItem[SelectedItems.Count];
              for (var i = 0; i <= SelectedItems.Count - 1; i++)
            sel[i] = SelectedItems[i];

              int min = -1;
              int max = -1;

              for (var i = 0; i < sel.GetLength(0); i++)
              {
            ListViewItem dragItem = sel[i];

            dragItem.Selected = false;
            int itemIndex = dragIndex;

            if (itemIndex == dragItem.Index)
              return;

            if (dragItem.Index < itemIndex)
              itemIndex++;
            else
              itemIndex = dragIndex + i;

            var insertItem = (ListViewItem) dragItem.Clone();
            insertItem.Selected = true;

            int oldidx = dragItem.Index;
            int newidx = itemIndex;

            Items.Insert(itemIndex, insertItem);
            Items.Remove(dragItem);

            if ((min == -1) || (Math.Min(oldidx, newidx) < min))
              min = Math.Min(oldidx, newidx);

            if ((max == -1) || (Math.Max(oldidx, newidx) > max))
              max = Math.Max(oldidx, newidx);

            if (AfterDragAndDropItem != null)
              AfterDragAndDropItem(this, new AfterDragAndDropItemEventArgs(insertItem, oldidx, newidx));
              }

              if (AfterDragAndDrop != null)
            AfterDragAndDrop(this, new AfterDragAndDropEventArgs(min, max));
        }
开发者ID:smejko80,项目名称:samschanneledit,代码行数:62,代码来源:ListViewDragAndDrop.cs

示例9: mnMoveTo_Click

        private void mnMoveTo_Click(object sender, EventArgs e)
        {
            var f = new FInputBox();
              if (f.Demana("Position", "New position :", "0") != DialogResult.OK)
            return;

              int newpos;
              if (!int.TryParse(f.Value, out newpos))
              {
            MessageBox.Show("Invalid number");
            return;
              }

              if (newpos <= 0)
            newpos = 1;

              if (newpos > listView1.Items.Count)
            newpos = listView1.Items.Count;

              var minIndex = -1;
              var maxIndex = -1;
              var dragIndex = newpos - 1;

              var sel = new ListViewItem[listView1.SelectedItems.Count];
              for (var i = 0; i <= listView1.SelectedItems.Count - 1; i++)
            sel[i] = listView1.SelectedItems[i];

              for (var i = 0; i < sel.GetLength(0); i++)
              {
            var dragItem = sel[i];
            var itemIndex = dragIndex;

            if (dragItem.Index < itemIndex)
              itemIndex++;
            else
              itemIndex = dragIndex + i;

            var insertItem = (ListViewItem)dragItem.Clone();

            var oldidx = dragItem.Index;
            var newidx = itemIndex;

            if ((minIndex == -1) || (Math.Min(oldidx, newidx) < minIndex))
              minIndex = Math.Min(oldidx, newidx);

            if ((maxIndex == -1) || (Math.Max(oldidx, newidx) > maxIndex))
              maxIndex = Math.Max(oldidx, newidx);

            if (newpos >= listView1.Items.Count) // Add to end
              listView1.Items.Add(insertItem);
            else
              listView1.Items.Insert(itemIndex, insertItem); // insert into position

            listView1.Items.Remove(dragItem);
              }

              RenumberChannels(minIndex, maxIndex);
        }
开发者ID:Tiggor,项目名称:samschanneledit,代码行数:58,代码来源:UCSingleEdit.cs

示例10: codeOutput_DragDrop

 private void codeOutput_DragDrop(object sender, DragEventArgs e)
 {
     //Return if the items are not selected in the ListView control.
     if (codeOutput.SelectedItems.Count == 0)
     {
         return;
     }
     //Returns the location of the mouse pointer in the ListView control.
     System.Drawing.Point cp = codeOutput.PointToClient(new System.Drawing.Point(e.X, e.Y));
     //Obtain the item that is located at the specified location of the mouse pointer.
     ListViewItem dragToItem = codeOutput.GetItemAt(cp.X, cp.Y);
     if (dragToItem == null)
     {
         return;
     }
     //Obtain the index of the item at the mouse pointer.
     int dragToIndex = dragToItem.Index;
     ListViewItem[] sel = new ListViewItem[codeOutput.SelectedItems.Count];
     for (int i = 0; i <= codeOutput.SelectedItems.Count - 1; i++)
     {
         sel[i] = codeOutput.SelectedItems[i];
     }
     bool modified = false;
     for (int i = 0; i < sel.GetLength(0); i++)
     {
         //Obtain the ListViewItem to be dragged to the target location.
         ListViewItem dragItem = sel[i];
         int itemIndex = dragToIndex;
         if (itemIndex == dragItem.Index)
         {
             return;
         }
         if (dragItem.Index < itemIndex)
             itemIndex++;
         else
             itemIndex = dragToIndex + i;
         //Insert the item at the mouse pointer.
         int dragPosition = dragItem.Index;
         ListViewItem insertItem = (ListViewItem)dragItem.Clone();
         codeOutput.SelectedItems.Clear();
         codeOutput.Items.Insert(itemIndex, insertItem);
         //Removes the item from the initial location while
         //the item is moved to the new location.
         codeOutput.Items.Remove(dragItem);
         modified = true;
     }
     if (modified)
         SendModified();
     //PSelectedIndex = -1;
     codeOutput.Items[dragToIndex].Selected = true;
     codeOutput.FocusedItem = codeOutput.SelectedItems[0];
     //codeOutput_SelectedIndexChanged(sender, e);
     //codeValues.Text = "";
     //codeValues.Enabled = false;
     codeOutput.Click += codeOutput_SelectedIndexChanged;
 }
开发者ID:dantarion,项目名称:tcp-gecko-dotnet,代码行数:56,代码来源:codecontroller.cs

示例11: KaiListView_DragDrop

        private void KaiListView_DragDrop(object sender, DragEventArgs e)
        {
            if (SelectedItems.Count == 0)
            {
                return;
            }

            Point pt = PointToClient (new Point(e.X, e.Y));
            ListViewItem lviDragTarget = GetItemAt (pt.X, pt.Y);
            if (null == lviDragTarget)
            {
                return;
            }

            ListViewItem[] arrlviSelected = new ListViewItem[SelectedItems.Count];
            for (int iItem = 0; iItem <= SelectedItems.Count - 1; iItem++)
            {
                arrlviSelected[iItem] = SelectedItems[iItem];
            }

            int iInsertAt = lviDragTarget.Index;
            for (int iItem = 0; iItem < arrlviSelected.GetLength(0); iItem++)
            {
                ListViewItem lviDragItem = arrlviSelected[iItem];
                if (iInsertAt == lviDragItem.Index)
                {
                    return;
                }
                if (lviDragTarget.Index > lviDragItem.Index)
                {
                    iInsertAt++;
                }
                else
                {
                    iInsertAt = lviDragTarget.Index + iItem;
                }

                Items.Insert(iInsertAt, (ListViewItem)lviDragItem.Clone());
                Items.Remove(lviDragItem);
            }
        }
开发者ID:kbogatyrev,项目名称:Kai,代码行数:41,代码来源:KaiListView.cs


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