/// <summary>
/// 取ListBox选中项id
/// </summary>
/// <returns>id数组</returns>
private int[] GetIDS()
{
int[] id = new int[listBox1SelectedIndicesCount];
for (int i = 0; i < listBox1SelectedIndicesCount; i++)
{
id[i] = (int)listBox1SelectedIndices[i];
}
return id;
} GetIDS()取出来的是选中项ID数组,你可以用循环遍历出来:int[] id=GetIDS();
textBox1Clear();
for (int i = 0; i<idLength; i++)
{
textBox1Text += id[i]ToString();
}
你应该用百分比,而不应该用或固定值
上面的代码的意思是第一列的长度为300的20%即60,第二列的长度为300的50%,
当然,你可以把width="300"去掉,这样列的长度就由上一级容器的长度决定,要是上一级还没有长度就继续寻找上一级,直到到达根元素
你的意思是在listbox选中不同的路径,在image控件预览? 可以绑定,但是要注意你选中的值是string类型的,而的source是BitmapImage,所以要定义一个Converter来转换。
可以定义类似如下的style
<Grid><GridResources>
<Style x:Key="SelectStyle" TargetType="TreeViewItem">
<Setter Property="IsSelected" Value="{Binding 你的属性}">
</Setter>
</Style>
</GridResources>
<TreeView>
</TreeView>
</Grid>
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);
}
ListBox增加值的时候,可以增加一个Value,一个Text,Text就是显示出来的,Value是看不到的,比如你存一个人,就可以存人的ID和人的NAME,这样可以取到ID来唯一确定一个人了。
ListBoxItemsAdd((new
ListItem("姓名","id"));
显示出来的就是“姓名”,可以用
ListBoxSelectedItemText获得“姓名”
ListBoxSelectedItemValue获得"id"
以上就是关于c#中如何获取listbox的多选的值(实际值ValueMembet)全部的内容,包括:c#中如何获取listbox的多选的值(实际值ValueMembet)、wpf 在listBox后台怎么取Template里面元素的值、wpf中如何绑定到listbox中的选定项等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)