How to add ListView selected items in other ListView?
Example project:
ExpTreeLib
Put this form ListView2 and add lv.selectedItems.
Thanks in advance.
You can use this method to add the items
ListView list = new ListView();
ListViewItem item = new ListViewItem();
// add them
list.Items.Add(item);
This would be enough, now you can use a simple loop for each element to add it to that list.
foreach (ListViewItem item in ListView.SelectedItems) {
// create a new list, or use currently present list
// add each item to it using .Add() method.
}
Related
My problem is; When click a button I input items in List, next in DropDownList. Problem is where i click button again exist items again into my DropDown.
How to solve this problem(sorry for image)?
List<string> companyList = new List<string>();
foreach (string item in companyList.ToList())
{
companyList.Remove(item); ----> this not working.......
}
foreach (SPListItem item in myItemCol)
{
companyList.Add(item["Company"].ToString());
}
companyList.Sort();
foreach (string item in companyList.Distinct())
{
ddComFilter.Items.Add(item.ToString());
}
You can use the Contains method to check if it is already there
if(!ddComFilter.Items.Contains(items.ToString())
{
ddComFilter.Items.Add(item.ToString());
}
This will only add the item if it is not already in the dropdown
You could check for existence of the item before add it to the list.
foreach (SPListItem item in myItemCol)
{
if(!companyList.Contains(item["Company"].ToString())
{
companyList.Add(item["Company"].ToString());
}
}
Then you need to clear the ddComFilter before adding the values to it:
companyList.Sort();
ddComFilter.Items.Clear();
foreach (string item in companyList.Distinct())
{
ddComFilter.Items.Add(item.ToString());
}
Alternate solution:
You can bind the ddComFilter using the generated list, instead for iterating the collection and add one-by-one. if so you need not to clear the collection, remove items etc. The code for this will be:
ddComFilter.Datasource = companyList;
ddComFilter.DataBind();
Here is an useful article for you
You should clear your dropdown before adding list as items:
companyList.Sort();
ddComFilter.Items.Clear(); // clear
foreach (string item in companyList.Distinct())
{
ddComFilter.Items.Add(item.ToString());
}
When you sort a List View why cant you sort it again there after?
The listbox holds Check boxes which are dynamically added.
(XAML)
<ListView Name="Main_List_View" />
(C#)
//The Dictionary list is being populated before this loop is run
Dictionary<string,string> list = new Dictionary<string,string>();
foreach(var item in list)
{
CheckBox box = new CheckBox();
box.Name = item.Key;
box.Content = item.Value;
Main_List_View.Items.Add(box);
}
Cool I loaded the list view with items now I sort them.
(C#)
Main_List_View.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Ascending));
The list is now sorted in Ascending successfully in Runtime.
But As soon as I Sort the same listview to Descending with a button Nothing Happens what could it be the reason?
(C#)
//Button event here
Main_List_View.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Descending));
Before you add Descending SortDescription, clear the available SortDescriptions.
Main_List_View.Items.SortDescriptions.Clear();
Main_List_View.Items.SortDescriptions.Add(new SortDescription("Content", ListSortDirection.Descending));
Background:
I have lists which store parsed data from sqlite columns. I want to show these lists in a listview to the user. They click a button and the list view should show these 3 lists and their contents.
The three lists are called, SeqIrregularities, MaxLen, and PercentPopList.
Problem: The listview is being populated in a horizontal manner (Shown below) which only contains contents of Seqirregularities list.The other 2 don't even show up. I want the listview to have contents of each list, vertically in the corresponding list column.
Side note: The listview is skipping the first column, another problem, but I can fix that.
Here's the code:
ListViewItem lvi = new ListViewItem();
foreach (object o in SeqIrregularities )
{
lvi.SubItems.Add(o.ToString());
}
foreach (object a in MaxLen )
{
lvi.SubItems.Add(a.ToString());
}
foreach (object b in PercentPopList)
{
lvi.SubItems.Add(b.ToString());
}
listView1.Items.Add(lvi);
If you are adding items to ListViewItem object and assigning it to ListView it will create a single row because ListViewItem represents one row in ListView. from your code you are adding ListViewItem only one time, hence you will get only one Row that is Horizontally.
if you need to get the Multiple Rows (Vertically) you need to add the multiple ListViewItem objects to ListView .
ListViewItem lvi = new ListViewItem();
foreach (object o in SeqIrregularities )
{
lvi.SubItems.Add(o.ToString());
}
listView1.Items.Add(lvi);//Adds a new row
lvi = new ListViewItem();
foreach (object a in MaxLen )
{
lvi.SubItems.Add(a.ToString());
}
listView1.Items.Add(lvi);//Adds a new row
lvi = new ListViewItem();
foreach (object b in PercentPopList)
{
lvi.SubItems.Add(b.ToString());
}
listView1.Items.Add(lvi);//Adds a new row
So I have the following code:
listView1.Items.Add("Test");
ListViewItem testing = new ListViewItem();
testing.SubItems.Add("Test2");
listView.Items.Add(testing);
And here's what it produces:
(source: gyazo.com)
Not sure why the "Test2" goes at the bottom.
First of all Both list view are same listView1 and listView?
If yes then here is the Answer:
listView1.Items.Add("Test");
while wrting this line of code you are adding first item in List view with main item "Test" and all subitems empty.
listView.Items.Add(testing);
After doing this you are adding second item in the list view with main item Empty and first subitem as "Test2"
To add one item in listView with subitem try this:
ListViewItem testing = new ListViewItem();
testing.Text="Test";
testing.SubItems.Add("Test2");
listView.Items.Add(testing);
I want to reach checked rows item in ASP.Net Listview control.
For example:
if 3 Lines of Listview checked, I want to reach checked items value in listview.
How can I do this?
Thanks.
You can use listview property 'CheckedItems'.
You can get list of items which are checked using listview.CheckedItems. For the value in that item, based on the subitem index you need to fetch it. For ex.
ListView.CheckedListViewItemCollection checkedItems =
ListView1.CheckedItems;
foreach ( ListViewItem item in checkedItems )
{
value = item.SubItems[1].Text;
}