I'm trying to update this Listbox in C#. This is my first program in C#, not exactly sure how things work.
public partial class progHider : Form
{
String[] processList;
public progHider()
{
InitializeComponent();
}
private void progHider_Load(object sender, EventArgs e)
{
List.Items.AddRange(getList());
}
private String[] getList()
{
Process[] processlist = Process.GetProcesses();
processList = new String[Process.GetProcesses().Length];
int index = 0;
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
processList[index] = process.MainWindowTitle;
index++;
}
}
return processList;
}
private void btnrefresh_Click(object sender, EventArgs e)
{
List.DataSource = null;
this.Update();
}
So the refresh button is suppose to update the Listbox by calling getList(), but I'm not sure how to get it done. In java, you just need to call the method and do repaint(). I tried this.refresh/update, no use. One question is how do I update Listbox? I can't figure out how to accomplish it.
Am I even doing this right? Should List.Items.AddRange(getList()); be in the progHider_Load method? Another question is, how does private void progHider_Load(object sender, EventArgs e) work? Is it only used once? can you call it? Also, where is the Main method? I'm using Visual Studio 2010 windows application mode, it just shows me the code for the partial class.