虾米@ 2018-03-29 01:27 采纳率: 11.1%
浏览 636
已结题

删除集合中当前选中的项怎么实现

.net写的程序,遇到点问题
A页面中相关代码
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.chId = new System.Windows.Forms.ColumnHeader();
this.chType = new System.Windows.Forms.ColumnHeader();
this.chEquName = new System.Windows.Forms.ColumnHeader();
this.chEquKMLabel = new System.Windows.Forms.ColumnHeader();
this.chDetail = new System.Windows.Forms.ColumnHeader();
this.chTime = new System.Windows.Forms.ColumnHeader();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tsmClearAll = new System.Windows.Forms.ToolStripMenuItem();
//this.tsmClear = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// chId
//
this.chId.Text = "";
this.chId.Width = 20;
//
// chType
//
this.chType.Text = "类型";
this.chType.Width = 40;
//
// chEquName
//
this.chEquName.Text = "设备名称";
this.chEquName.Width = 120;
//
// chEquKMLabel
//
this.chEquKMLabel.Text = "公里标";
this.chEquKMLabel.Width = 120;
//
// chDetail
//
this.chDetail.Text = "详细内容";
//
// chTime
//
this.chTime.Text = "时间";
this.chTime.Width = 120;
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.tsmClearAll});
// this.tsmClearAll});

        this.contextMenuStrip1.Name = "contextMenuStrip1";
        this.contextMenuStrip1.Size = new System.Drawing.Size(149, 26);
        this.contextMenuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ContextMenuStrip_ItemClicked);
        // 
        // tsmClearAll
        // 
        this.tsmClearAll.Image = global::StationMachinApp.Properties.Resources.DeleteHS;
        this.tsmClearAll.Name = "tsmClearAll";
        this.tsmClearAll.Size = new System.Drawing.Size(148, 22);
        this.tsmClearAll.Text = "清除数据";
        // 
        // SubListView
        // 
        this.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.chId,
        this.chType,
        this.chEquName,
        this.chEquKMLabel,
        this.chTime,
        this.chDetail});
        this.ContextMenuStrip = this.contextMenuStrip1;
        this.Dock = System.Windows.Forms.DockStyle.Fill;
        this.FullRowSelect = true;
        this.GridLines = true;
        this.View = System.Windows.Forms.View.Details;
        this.SizeChanged += new System.EventHandler(this.SubListView_SizeChanged);
        this.contextMenuStrip1.ResumeLayout(false);
        this.ResumeLayout(false);

    }

                    #endregion

    private System.Windows.Forms.ColumnHeader chId;
    private System.Windows.Forms.ColumnHeader chType;
    private System.Windows.Forms.ColumnHeader chEquName;
    private System.Windows.Forms.ColumnHeader chEquKMLabel;
    private System.Windows.Forms.ColumnHeader chDetail;
    private System.Windows.Forms.ColumnHeader chTime;
    private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
    private System.Windows.Forms.ToolStripMenuItem tsmClearAll;

            B页面中的清除方法

                    private void ContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {
        if (e.ClickedItem.Name.Equals("tsmClearAll"))
        {

            this.Items.Clear();


        }
    }

            这样的结果是选中的是选中当前行,点击“清除数据”时,是将整个集合清空了,而非是将当前选中的项清理掉,请大神们帮忙看看,怎样改才能清除当前选中的项。
  • 写回答

4条回答 默认 最新

  • 关注

    在for循环中操作list 并移除list中的项 如果for循环正序 当删除的时候 list的坐标会产生变化 会导致越界的问题

    我们可以倒叙删除

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码