Hi,
I am working with listview using c#.In the listview,there exists 2 columns namely Profile and Status.Here i am populating listview by retrieving the values from a text file.So,for example.Consider column profile consists of items 1,2,3... and status contains in use,initialise such as
Profile Status
-------- ------
1 in use
2 initialise
3 initialise
in this way,listview will be existed.Here i have 2 buttons Use,Initialise.When i click on listview items which is of status "initialise" and by clicking on Use button,status must change to state "in use".Totally in listview,there must be a single state "in use".But i am not able to get.Now i want to collect the selected item value in Use button,non-selected item value in initialise button.How is it possible?
Loading
saradaPosted Aug 13, 2009, 12:34 AM
i am using txtfile to populate listview.so the code which you have given is not working for my listview problem.When i click on the listview item and by clicking on use button which is in the same form,the listview status must be changed in the txtfile.Then the same data will be binded to listview.This is the thing i wanted.Can u help me
Master BillaPosted Aug 12, 2009, 4:43 AM
Just few line code to do this
private void btnInit_Click(object sender, EventArgs e)
{
int selectedIndex = listView2.SelectedIndices[0];
if (selectedIndex >= -1)
{
ListViewItem item = listView2.Items[selectedIndex];
item.SubItems.RemoveAt(0);
if (item.SubItems[0].Text == "Init")
{
item.SubItems.Insert(1, new ListViewItem.ListViewSubItem(item, "In use"));
}
listView2.Items.RemoveAt(selectedIndex);
listView2.Items.Insert(selectedIndex, item);
}
}
private void btnInuse_Click(object sender, EventArgs e)
{
int selectedIndex = listView2.SelectedIndices[0];
if (selectedIndex >= -1)
{
ListViewItem item = listView2.Items[selectedIndex];
item.SubItems.RemoveAt(0);
if (item.SubItems[0].Text == "In use")
{
item.SubItems.Insert(1, new ListViewItem.ListViewSubItem(item, "Init"));
}
listView2.Items.RemoveAt(selectedIndex);
listView2.Items.Insert(selectedIndex, item);
}
}
Roei BarPosted Aug 12, 2009, 2:14 AM
Mark this as "Accepted Answer" if you liked it
saradaPosted Aug 12, 2009, 1:54 AM
button was not represented inside the listview.It is outside the listview but with in the same form
Master BillaPosted Aug 12, 2009, 1:46 AM
I have a quick question, button are represent in list view Item(status)
cell1=normal
cell2=button(this is Button control)
i'm building code for you, Please reply ASAP
thank you