hello
i have Listview his name is listView1 i try to refresh my listview1 but that not work!!!
i just see the sam details and that no update.
i try this : listView1.Update() and also listView1.Refresh() and that not work!!!
the code here:

file EditSelectedItem.cs

private void button1_Click(object sender, EventArgs e)
        {     
                EditData ed = new EditData(); // call for the form the open right now with the listview.
                ed.TryIt(); // call for this function that update the listview
                 this.Close();
        }

file EditData.cs // that open when i use the EditSelectedItem

public void TryIt()
{
..../
                listView.Clear();
                foreach (DataRow row in ds.Tables[0].Rows) // update listview1
                {
                    ListViewItem item1 = new ListViewItem(c.ToString());                   
                    item1.SubItems.Add(row["Name"].ToString());
                    item1.SubItems.Add(row["LastName"].ToString());
                    item1.SubItems.Add(row["Password"].ToString());
                    item1.SubItems.Add(row["Notes"].ToString());
                    listView1.Items.Add(item1);
                    c++;
                }
                listView1.Refresh();
}

and the problem that i dont see the update in the listView1. whats the problem with my code?
thanks...

You have to pass the DataTable from form where button1 is located (form1 or whatever) to EditData class:

DataTable table;

private void FillDataTable()
{
      table = new DataTable();
      //fill it here...
}
private void button1_Click(object sender, EventArgs e)
{     
    EditData ed = new EditData(); 
    ed.TryIt(table); //pass data as argument
    this.Close(); //I dont know why you close, but ok...
}
//class EditData
class EditData  //is this a Form class (because if its not, you cannot use ListView control 
                //just asking...
{
     public EditData()
     {
          //create columns for listView:
          listView1.Columns.Add("id", 50, HorizontalAlignment.Left);
          listView1.Columns.Add("Name", 80, HorizontalAlignment.Left);
          //and so on...
     }
 
     public void TryIt()
     {
           int c = 1;
           listView.Clear();
           foreach (DataRow row in ds.Tables[0].Rows) // update listview1
           {
                ListViewItem item1 = new ListViewItem(c.ToString());                   
                item1.SubItems.Add(row["Name"].ToString());
                item1.SubItems.Add(row["LastName"].ToString());
                item1.SubItems.Add(row["Password"].ToString());
                item1.SubItems.Add(row["Notes"].ToString());
                listView1.Items.Add(item1);
                c++;
           }
     }
}

EditData == Form1
EditSelectedItem == Form2
when i click the Button in Form2(to save the data that the user input) i open the function in Form1(to update the listView1) and close the Form2. now i want to see the update details in the listview in Form1(but also that the function work the details in the listview not changed).
you doing that all the code in one Form but it didnt.. by the way i pass the DataTable but i dont show here all the code/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.