I am attempting to pull in a list of printers on a persons computer and give that person the ability to select a printer. I am using a ComboBox to display the list of installed printers (but have tried multiple other Controls).
I have placed this code in several areas in an attempt to solve this issue:
private void PrintForm_Load(object sender, EventArgs e)
{
foreach (string my_installed_printers in PrinterSettings.InstalledPrinters)
{
printer_list.Items.Add(my_installed_printers);
}
}
Here is my code for detecting the index changing:
private void printer_list_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine("SelectedIndex: " + printer_list.SelectedIndex);
Console.WriteLine("SelectedItem: " + printer_list.SelectedItem);
Console.WriteLine("SelectedValue: " + printer_list.SelectedValue);
Console.Write("Items: ");
foreach (string my_item in printer_list.Items)
{
Console.Write(my_item + ", ");
}
Console.WriteLine();
}
It always returns:
SelectedIndex: -1 SelectedItem: SelectedValue: Items:
The strange thing is that I can still see all of the items in the ComboBox, but I cannot seem to refer to them in the code. The program doesn't think they exist. I am still pretty new with C# so I really appreciate the help.