Click here to Skip to main content
15,908,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to convert the combobox into a checklistbox . It is possible to debug of some codes to convert into checklistbox. ? someone can help me ?

here's my codes:
C#
private void Form1_Load(object sender, EventArgs e)
{
//See if any printers are installed
if (PrinterSettings.InstalledPrinters.Count <= 0)
{
MessageBox.Show("Printer not found!");
return;
}

//Get all available printers and add them to the combo box
foreach (String printer in PrinterSettings.InstalledPrinters)
{
comboBox1.Items.Add(printer.ToString());
}
}

private void button1_Click(object sender, EventArgs e)
{
//Create a PrintDocument object
PrintDocument pd = new PrintDocument();

//Set PrinterName as the selected printer in the printers list
pd.PrinterSettings.PrinterName = comboBox1.SelectedItem.ToString();

//Add PrintPage event handler
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

//Print the document
pd.Print();
}

//The PrintPage event handler 
public void pd_PrintPage(object sender, PrintPageEventArgs ev)
{

//Get the Graphics object
Graphics g = ev.Graphics;

//Create a font Arial with size 16
Font font = new Font("Arial", 16);

//Create a solid brush with black color
SolidBrush brush = new SolidBrush(Color.Black);

//Draw "Hello Printer!";
g.DrawString("Hello Printer!",
font, brush,
new Rectangle(20, 20, 200, 100));
}
}
Posted
Updated 19-Jan-14 5:40am
v2
Comments
Rahul VB 19-Jan-14 14:17pm    
Hello,

Do you want to render items of a combobox into a checklistbox?

Thanks,
- Rahul
BillWoodruff 19-Jan-14 16:40pm    
A CheckedListBox is a more complex Control than the simple ComboBox, supporting 'SelectionMode, multiple Columns, etc. as well as CheckBoxes, but you can pretty much use it directly as a substitute for a ComboBox.

What problems are you having using the CheckedListBox ?
sahabiswarup 20-Jan-14 0:51am    
i think you want to add printer in checkbox list, you may add them in checkboxlist like this way
for (int Index = 0; Index <= dt.Rows.Count-1; Index++)
{
chkList1 = new CheckBox();
chkList1.Text = dt.Rows[Index][1].ToString();
chkList1.ID = dt.Rows[Index][0].ToString();
Pnl.Controls.Add(chkList1);
Pnl.Controls.Add(new LiteralControl(""));
}
and to get the printer list from checkboxlist you need to add this event
protected void chkList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < chkList1.Items.Count; i++)
{
if (chkList1.Items[i].Selected == true)
{
//add your logic to get selected printer list
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900