Listview获取选中行的值


一般情况请注意别先删除了选中行,又去使用。那就会导致找不到选中行。。。。。哥犯了这个错误。。。找了很长时间问题

if (this.lstwlview.SelectedIndices.Count > 0)
            {
                if (MessageBox.Show("确认删除该条码?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                {
                     //获得选择的序列号
                    string ss = "";
                    if (lstwlview.SelectedIndices != null && lstwlview.SelectedIndices.Count>0)
                    {
                        ListView.SelectedIndexCollection c = lstwlview.SelectedIndices;
                        ss = lstwlview.Items[c[1]].Text;

                        //ss = lstwlview.Items[c[0]].SubItems[1].Text;// 表示选中行的第二列
                        MessageBox.Show(ss);
                    }
                }
            }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM