//判断listview选中行的个数是否大于0(意味着至少选中了一行)
if
(listView1SelectedIndices
!=
null
&&
listView1SelectedIndicesCount
>
0)
{
string
tag
=
listView1FocusedItemTagToString();
//取得选中行的tag
string
text1= listView1FocusedItemSubItems[0]Text;
//取得选中行第一列的值
}
直接用下面的代码就能取得某个项目相对于listview的坐标,再计算一下就能得到某个项目相对于屏幕或窗体的具体坐标了,干嘛一定要用API解决呢?
1listviewView等于Details时,
Rectangle rect = listView1Items[0]SubItems[0]Bounds;
MessageBoxShow(rectXToString() + ", " + rectYToString());
2。listviewView等于其他值时,
Rectangle rect = listView1Items[0]Bounds;
MessageBoxShow(rectXToString() + ", " + rectYToString());
莫非你是想说获取其他程序中的listview的某个项目的坐标?如果是这样的话我就不知道了,没研究过
得到listview中的itemview具体方法如下:
在getView()方法中,给convert View设置setTag(),可以将position或者view设置完成后进去,然后在on Click方法中通过getTag()获得所设置的值,就完成获取任务了。
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);
}
void ListView_GetItemText(HWND hwnd,
int iItem,//行索引
int iSubItem,//列索引
LPTSTR pszText,int cchTextMax
);
char szRet[128];
ListView_GetItemText(hListView,3,5,szRet,128);//获取第三行,第五列的文本
以上就是关于C#中listview如何取得选中行的值全部的内容,包括:C#中listview如何取得选中行的值、如何获得某个程序中的listview的某个项目的坐标、怎么拿到listview的item值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)