Good day,
I'm new to whole programming thing and can't figure out / find a solution.
I've been trying to populate my ListView with Items that come from another Class.
But the ListView doesn't seem to do anything when the Class2
returns an Array
.
Here is how i make it :
1 ) I search for something and send the value to Class2
( Main Class in Form1 ):
private void tbSearch_KeyDown(object sender, KeyEventArgs e)
{
Class2 cl2 = new Class2();
if (e.KeyCode == Keys.Enter)
{
if (string.IsNullOrEmpty(tbSearch.Text))
{
MessageBox.Show("The Textbox is Empty.....");
}
else
{
listV.Items.Clear();
cl2.Search(tbSearch.Text); // Give a value to Method in Class2
}
}
}
2 ) Then in Class2
i do some internet search and return arrays
with the Results :
public async void Search(string search_value)
{
/*** Read the XML Data that i've got from Response ****/
foreach (XmlNode node in XMLlist)
{
/****** Get the values that i need and write them into an array *******/
string[] result = new string[10];
result[0] = series_title;
result[1] = series_type;
result[2] = series_episodes;
result[3] = series_score;
result[4] = series_id;
result[5] = series_title_english;
result[6] = series_status;
result[7] = series_start_date;
result[8] = series_end_date;
result[9] = series_image;
Form1 fm1 = new Form1();
fm1.Update_SearchList(result); // Return an array to Form1
}
}
3) And at the end i try to populate the ListView with the returned array
( Form1 again ) :
public void Update_SearchList(string [] array)
{
ListViewItem item = new ListViewItem(array);
this.listV.BeginUpdate();
this.listV.Items.Add(item); // Here the Item.Add() Method doesn't add new Items to the ListView or they just aren't being shown.
this.listV.EndUpdate();
}
The listView.View
is set to Details
and the columns are being generated on Form.Load
.
Is there a problem with how i execute the listView.Items.Add();
Method or is there another problem ?
When i try to do this whole operation in one single private void tbSearch_KeyDown(object sender, KeyEventArgs e)
everythings works.
Thank you for your time and have a good day !