0
I’m developing an inventory manager, and the data is being stored in a database. The problem I’m facing is this: when I add a new product for example, I created a "Update list" button (I left it in red on the image), which when the user clicks on it, it updates the Listview and shows the new product inserted.
The following happens, when the person clicks on "New product" (to add a new product), opens a new form to register. What I am trying to do is to update the Listview of the products (which is in Form1), when the user registers a product by form2. I have already tried to instantiate the Form1 class and call the method, not any error, but the Listview of the products does not update. How can I resolve?
Method to update the Listview I’m using:
// Método para atualizar a ListView Produtos
public void RefreshList()
{
// Limpar o campo da List View
listView_Cliente.Items.Clear();
// Lógica para atualizar a list view
con.Open();
cmdListView = new SqlCommand("select * from produtos", con);
da = new SqlDataAdapter(cmdListView);
ds = new DataSet();
da.Fill(ds, "estoque");
con.Close();
dt = ds.Tables["estoque"];
int i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
listView_Cliente.Items.Add(dt.Rows[i].ItemArray[0].ToString());
// temos 4 colunas (sendo uma a ID), então aqui só criamos 3, a ID vai automática
listView_Cliente.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
listView_Cliente.Items[i].SubItems.Add(dt.Rows[i].ItemArray[2].ToString());
listView_Cliente.Items[i].SubItems.Add(dt.Rows[i].ItemArray[3].ToString());
listView_Cliente.Items[i].SubItems.Add(dt.Rows[i].ItemArray[4].ToString());
}
}
Basically then I entered the class of Form1 (which is the method to update Listview) to form2, there I called the method to update Listview, Visual Studio did not present errors, however, List View does not update. I tried to do other ways in some gringas posts that I saw, however, also without success. I appreciate any help!
Already tried to call the update list method at the end of the registration method?
– RXSD
I tried, not from the bug either, but it doesn’t update. Do I have to make any changes to the code so that it identifies the Listview I want to update is in another form? I’m doing it this way: 1. I present the class that has the method and the List View: Telalogado updateTop = new Telalogado(); 2. I call the method on the instantiated object (within the sign-up method): updateStock.Refreshlist()
– Gabriel
You don’t need to run the
Bind()
component after updating your items?– Leandro Angelo