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;
        }               
查看全部
shy_2008
Lstevev
2015/06/06 06:19
  • c#
  • 点赞
  • 收藏
  • 回答
    私信

5个回复