C#如何获取listview选中项

C#如何获取listview选中项,第1张

foreach(ListViewItem item in listviewItems)

{

if(listviewItemsChecked == true)

{

string message = “”;

}

}

private void CreateMyListView()

{

// Create a new ListView control

ListView listView1 = new ListView();

listView1Bounds = new Rectangle(new Point(10,10), new Size(300,200));

// Set the view to show details

listView1View = ViewDetails;

// Allow the user to edit item text

listView1LabelEdit = true;

// Allow the user to rearrange columns

listView1AllowColumnReorder = true;

// Display check boxes

listView1CheckBoxes = true;

// Select the item and subitems when selection is made

listView1FullRowSelect = true;

// Display grid lines

listView1GridLines = true;

// Sort the items in the list in ascending order

listView1Sorting = SortOrderAscending;

// Create three items and three sets of subitems for each item

ListViewItem item1 = new ListViewItem("item1",0);

// Place a check mark next to the item

item1Checked = true;

item1SubItemsAdd("1");

item1SubItemsAdd("2");

item1SubItemsAdd("3");

ListViewItem item2 = new ListViewItem("item2",1);

item2SubItemsAdd("4");

item2SubItemsAdd("5");

item2SubItemsAdd("6");

ListViewItem item3 = new ListViewItem("item3",0);

// Place a check mark next to the item

item3Checked = true;

item3SubItemsAdd("7");

item3SubItemsAdd("8");

item3SubItemsAdd("9");

// Create columns for the items and subitems

listView1ColumnsAdd("Item Column", -2, HorizontalAlignmentLeft);

listView1ColumnsAdd("Column 2", -2, HorizontalAlignmentLeft);

listView1ColumnsAdd("Column 3", -2, HorizontalAlignmentLeft);

listView1ColumnsAdd("Column 4", -2, HorizontalAlignmentCenter);

//Add the items to the ListView

listView1ItemsAddRange(new ListViewItem[]{item1,item2,item3});

// Create two ImageList objects

ImageList imageListSmall = new ImageList();

ImageList imageListLarge = new ImageList();

// Initialize the ImageList objects with bitmaps

imageListSmallImagesAdd(BitmapFromFile("C:\\MySmallImage1bmp"));

imageListSmallImagesAdd(BitmapFromFile("C:\\MySmallImage2bmp"));

imageListLargeImagesAdd(BitmapFromFile("C:\\MyLargeImage1bmp"));

imageListLargeImagesAdd(BitmapFromFile("C:\\MyLargeImage2bmp"));

//Assign the ImageList objects to the ListView

listView1LargeImageList = imageListLarge;

listView1SmallImageList = imageListSmall;

// Add the ListView to the control collection

thisControlsAdd(listView1);

}

您好,我来为您解答:

在ListView显示数据前,你应该建立一个数据备份,可以是链表,在显示后,链表中的项应该与ListView中的Item有个对应关系,这样就可以根据position从链表中查询相应的数据。

希望我的回答对你有帮助。

以上就是关于C#如何获取listview选中项全部的内容,包括:C#如何获取listview选中项、如何获得ListView中选中项的值、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9615511.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存