windows Forms下listView的使用

來源:互聯網
上載者:User
轉載自:http://student.csdn.net/space.php?uid=113202&do=blog&id=39978C#如何擷取listview選中項 懸賞分:30 - 解決時間:2009-10-3 01:06
RT,Listview中有9項,任意點擊一項請問要如何擷取,盡量講得具體些吧~謝謝啦~ 
最佳答案
選中項的文本值:this.listView1.SelectedItems[0].Text;選中項的子項的文本值this.listView1.SelectedItems[0].SubItems[0].Text;(SubItems[0]表示選中項的第一個子項,第二個子項就是SubItem[1],第三個就是SubItems[2]..
..以此類推) 

ListView用法範例程式碼

this.listView1.View = View.Details;
ListView listView1 = new ListView();

// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;

// Display check boxes. 是否顯示複選框
listView1.CheckBoxes = true;
// Select the item and subitems when selection is made. 是否選中整行
listView1.FullRowSelect = true;
// Display grid lines. 是否顯示網格
listView1.GridLines = true;
// Sort the items in the list in ascending order. 升序還是降序
listView1.Sorting = SortOrder.Ascending;
this.listView1.Columns.Add("編號", 60, HorizontalAlignment.Right);
this.listView1.Columns.Add("姓名", 60, HorizontalAlignment.Right);
this.listView1.Columns.Add("年齡", 60, HorizontalAlignment.Right);
this.listView1.Columns.Add("電話", 60, HorizontalAlignment.Right);
this.listView1.Visible = true;

for (int i = 20; i >= 1; i--)
{
ListViewItem li = new ListViewItem();
li.SubItems[0].Text = i.ToString();
li.SubItems.Add("aaa");
li.SubItems.Add("25");
li.SubItems.Add("11223344");
this.listView1.Items.Add(li);
}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.