Click here to Skip to main content
15,885,154 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I have some columns in listview like "ID1", "ID2", "ID3"....
And I want to clear (not delete) column1 which is "ID1" (or selected column) with a button
How can I do it?
Secondly How can delete number of listview.items.count cells from Column1?

As shown below figure I want to update my ID numbers after selected items deleted.

<img src="http://i.hizliresim.com/ydaAP0.png" />
Posted
Updated 9-Jun-14 3:37am
v3
Comments
Thanks7872 9-Jun-14 9:23am    
What do you mean by clear?
cengav4r 9-Jun-14 9:41am    
clear mean null :s

Hi,

You need to Google[^] this, you will find many solution.
 
Share this answer
 
Comments
cengav4r 9-Jun-14 8:07am    
I tried but could not find any solution. Article about delete or remove. I want to clear only 1. column
try this.. :)


C#
listView1.Columns["ID1"].Visible = false;

//or

listView1.Columns["ID1"].Width = 0;
 
Share this answer
 
v3
Comments
cengav4r 9-Jun-14 8:50am    
Hello,
Thanks for reply,
But as I mention above I dont want to delete or remove just wanna clear related column
have a nice day
Nirav Prabtani 9-Jun-14 9:29am    
try updated solution.. :)
<text>You may try with :
C#
for (int i = 0; i < listView1.Items.Count; i++ )
{
    if (listView1.Items[i].Selected)
    {
        listView1.Items[i].Remove();
        i--;
    }
}
 
Share this answer
 
Comments
cengav4r 9-Jun-14 9:34am    
I am sorry but your codes delete related row, but I want to modify on column. I renewed my question
Thank you for response
is this what you mean by clear without removing? Let me know.

C#
listView1.SelectedItems.Clear();
 
Share this answer
 
Comments
cengav4r 10-Jun-14 2:30am    
This is better;
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Selected)
{
listView1.Items[i].SubItems.Clear();
}
}
That code clear selecteditems (row). But I want to clear 1. column.Thanks for response
goathik 10-Jun-14 7:31am    
listView1.Columns[1].ListView.Items[i].SubItems.Clear();

did you try this? just a wild guess...
cengav4r 10-Jun-14 10:56am    
int newID = listView1.Items.Count;
for (int i = 1; i <= newID; i++)
{
listView1.Columns[0].ListView.Items[i-1].SubItems.Clear();
}
That code clear all column and row (very interestingly it should delete conly coloum0 with all rows). I had solved my problem pls look at above message
C#
if (listView1.Items.Count == 0) return;
         var col = listView1.Columns.Cast<ColumnHeader>()
                             .Select((x, i) => new { x, i })
                             .FirstOrDefault(a => a.x.Text == "ID");

         if (col == null) return;

         foreach (ListViewItem item in listView1.Items)
         {
             item.SubItems[col.i].Text = "";
         }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900