c#中怎么获取当前选中的listviewgroup中的第一个listviewitem

c#中怎么获取当前选中的listviewgroup中的第一个listviewitem,第1张

foreach (ListViewItem item in listView1Items)

{

if (itemChecked)

{

}

}

ListView默认情况当item有焦点时,item上的button等子控件获取不到焦点;当子控件有焦点时,item无焦点无法响应onItemClick事件ViewGroupFOCUS_AFTER_DESCENDANTS:表示item的子控件优先于item获得焦点;ViewGroupFOCUS_BEFORE_DESCENDANTS:表示item优先于其子控件获得焦点。解决法:[java]viewplaincopylistViewsetOnItemSelectedListener(onItemSelectedListener);privateAdapterViewOnItemSelectedListeneronItemSelectedListener=newAdapterViewOnItemSelectedListener(){@OverridepublicvoidonItemSelected(AdapterViewparent,Viewview,intposition,longid){//当此选中的item的子控件需要获得焦点时parentsetDescendantFocusability(ViewGroupFOCUS_BEFORE_DESCENDANTS);//elseparentsetDescendantFocusability(ViewGroupFOCUS_BEFORE_DESCENDANTS);}@OverridepublicvoidonNothingSelected(AdapterViewparent){parentsetDescendantFocusability(ViewGroupFOCUS_BEFORE_DESCENDANTS);}}

listviewsetOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<> parent, View view,

int position, long id) {

// position就是当前item的位置,通过这个position就可以得到显示这条数据的数据源

Object o = 数据集合get(position);

//再对这个o进行处理就可以了(该对象里面就有你需要的东西)

}

});

tableWidget_itemClicked(QTableWidgetItem item)

这里的item就是单击的项

还有获取当前项: ui->tableWidget->currentItem();

最近我也遇到这个问题,是这样解决的

var obj = documentgetElementById("textEMSid");

var itemValue = objvalue;//获取itemValue;

var itemLabel = objoptions[objselectedIndex]text;//获取itemLabel

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);

}

以上就是关于c#中怎么获取当前选中的listviewgroup中的第一个listviewitem全部的内容,包括:c#中怎么获取当前选中的listviewgroup中的第一个listviewitem、如何获取ListView里Item中的控件、给listview设置一个上下文菜单,然后长按listview后出现的上下文菜单标题上怎么得到关于选中的item的信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存