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

Master BillaRank #2,229 · 630 reputationPosted Aug 11, 2009, 9:46 PM EDT
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
sarada28 reputationPosted Aug 11, 2009, 9:54 PM EDT
button was not represented inside the listview.It is outside the listview but with in the same form
Roei BarRank #1,271 · 1.4K reputationPosted Aug 11, 2009, 10:14 PM EDT
const string IN_USE = "in use"; const string INITIALIZE = "initialize"; public Form1() { InitializeComponent(); bool flag = false; for (int i = 0; i < 10; i++) { ListViewItem lView = new ListViewItem(i.ToString()); if (flag) { lView.SubItems.Add(IN_USE); listView1.Items.Add(lView); flag = false; } else { lView.SubItems.Add(INITIALIZE); listView1.Items.Add(lView); flag = true; } } listView1.View = View.Details; } private void btnInit_Click(object sender, EventArgs e) { foreach (ListViewItem subItem in listView1.SelectedItems) { if (subItem.SubItems[1].Text == IN_USE) { subItem.SubItems[1].Text = INITIALIZE; } } } private void btnInUse_Click(object sender, EventArgs e) { foreach (ListViewItem subItem in listView1.SelectedItems) { if (subItem.SubItems[1].Text == INITIALIZE) { subItem.SubItems[1].Text = IN_USE; } } }Mark this as "Accepted Answer" if you liked it
Master BillaRank #2,229 · 630 reputationPosted Aug 12, 2009, 12:43 AM EDT
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);
}
}
sarada28 reputationPosted Aug 12, 2009, 8:34 PM EDT
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