C#listview 返回items.index

为什么listview无论点哪行items.index都返回0

         private void Hide_ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //隐藏数据
            if (MessageBox.Show("是否隐藏本条数据?", "提问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {

                int i_index = is_check_fun();
                string ttmid = listView1.Items[i_index].SubItems[0].Text;
                string userid = UserLoginInfo.CurrentUserInfo.Id.ToString();
                string sql = string.Format("EXECUTE [ysjk].[dbo].[SP_Hide_Show_Data] '{0}'  ,'{1}'  ,1", userid, ttmid);
                try
                {
                    SQLHelper.ExecuteSql(sql);
                    MessageBox.Show("本条数据已经被隐藏,本数据背景将以淡紫色显示。");
                    listView1.Items[i_index].BackColor = ColorTranslator.FromHtml("#ccccff");
                    //listView1.Items[listView1.Items.IndexOfKey(ttmid)].BackColor = ColorTranslator.FromHtml("#ccccff");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }




        private int is_check_fun()
        {
            if (listView1.Items.Count <= 0)
            {
                MessageBox.Show("没有数据,不能操作!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return -1;
            }
            if (listView1.SelectedItems.Count <= 0)
            {
                MessageBox.Show("没有选中一项!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return -1;
            }
            int index = listView1.SelectedItems[0].Index;
            return index;
        }               

你确定你注册是是行点击事件 不是 头部行 点击事件?

调试一下,看看, listView1.SelectedItems[0]是不是都长一样些死了返回

看看 listView1.SelectedItems[0]是不是都一样

这个问题 在IndexChanged 事件中就不会有错误,太奇怪了

遇到类似问题;
Items.Count一直等于0;
导致不会实现ListView根据项的数目多少来变化自身高度;