I have a problem with ListView. I am trying to call AddToListView function which is in UCForm from MainForm but nothing shows up on the ListView. Strangely, when I call AddToListView on UCForm initialization everything works correctly.
AddToListView function:
public void AddToListView()
{
var item1 = new ListViewItem(new[] { "text1", "text2", "text3", "text4" });
listView.Items.Add(item1);
}
Button click in MainForm:
UCForm uf = new UCForm();
private void btnAddToList_Click(object sender, EventArgs e)
{
uf.AddToListView();
}
More info: There are 4 columns already set up. FullRowSelect is set to true. GridLines are set to true.
What I've tried: Add item to ListView from another class
and How to access a ListView control on another form.
Both of the posts didn't help me. My goal is to add values to ListView from another class.