Im using foreach to loop through Win32_Printer properties and then im adding the properties values l

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
So instead see in the listbox only 50 properties i see like 200 i see the properties list then im scrolling down when im getting to the last property in the listbox the list start over again.
How do i make so it will add only once the properties values list to the listbox1?
ManagementObjectSearcher mosPrinter = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");<br/>

<br/>
foreach (ManagementObject moDiskete in mosPrinter.Get())<br/>
{

<br/>
foreach (PropertyData p in moDiskete.Properties)<br/>
{
listBox1.Items.Add(String.Format("{0}: {1}", p.Name, p.Value == null ? "NULL" : p.Value));

<br/>
}<br/>

<br/>

<br/>
label31.Text = "Showing The Chosen Device Information";<br/>
// label30.Text = moDiskete.GetPropertyValue["Parameters"].ToString();<br/>
//label29.Text = printer["Model"].ToString();<br/>
// label28.Text = moDisk["SerialNumber"].ToString();<br/>
//label27.Text = printer["InterfaceType"].ToString();<br/>
// The capacity in gigabytes is easily calculated<br/>
// label26.Text = printer["Size"].ToString() + " bytes (" + Math.Round(((((double)Convert.ToDouble(printer["Size"]) / 1024)
/ 1024) / 1024), 2) + " GB)";<br/>
// label25.Text = printer["Partitions"].ToString();<br/>
// label24.Text = printer["Signature"].ToString();<br/>
// label23.Text = moDisk["FirmwareRevision"].ToString();<br/>
// label22.Text = printer["TotalCylinders"].ToString();<br/>
// label21.Text = printer["TotalSectors"].ToString();<br/>
// label20.Text = printer["TotalHeads"].ToString();<br/>
// label19.Text = printer["TotalTracks"].ToString();<br/>
// label18.Text = printer["BytesPerSector"].ToString();<br/>
// label17.Text = printer["SectorsPerTrack"].ToString();<br/>
// label16.Text = printer["TracksPerCylinder"].ToString();
label1.Text = "Type: ";<br/>
label2.Text = "Model: ";<br/>
label3.Text = "Serial Number: ";<br/>
label4.Text = "Interface: ";<br/>
label5.Text = "Capacity: ";<br/>
label6.Text = "Partitions: ";<br/>
label7.Text = "Signature: ";<br/>
label8.Text = "Firmware: ";<br/>
label9.Text = "Cylinders: ";<br/>
label10.Text = "Sectors: ";<br/>
label11.Text = "Heads: ";<br/>
label12.Text = "Tracks: ";<br/>
label13.Text = "Bytes per Sector: ";<br/>
label14.Text = "Sectors per Track: ";<br/>
label15.Text = "Tracks per Cylinder: ";<br/>
}<br/>

The line im adding the properties list values is: <span style="font-size:x-small
<span style="font-size:x-small <font size="2
listBox1.Items.Add(
</font>



<span style="color:#2b91af; font-size:x-small <span style="color:#2b91af; font-size:x-small String<span style="font-size:x-small .Format(<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small "{0}:
{1}"<span style="font-size:x-small , p.Name, p.Value == <span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small null<span style="font-size:x-small ?
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small "NULL"<span style="font-size:x-small : p.Value));

Thanks for helping. <hr class="sig danieli

View the full article
 
Back
Top