Hey
I have 2 types of data, in the namespace System.Drawing.Printing:
Papersource.sourceName and Papersource.Kind.
SourceName gets the name og the papertrays from a printer, like "tray 1"
Kind gets the int value from the printer so fx. tray 1 have a kind value of 258.
in my combobox i only want to show the sourcenames, but if i choose "tray 1" i want to get a messagebox where i get the kind value of the sourcename.
Does anyone understand and have a example :)
Loading
VulpesPosted Dec 21, 2012, 10:44 AM
PrinterSettings ps = new PrinterSettings();
VulpesPosted Jan 11, 2013, 7:00 PM
jesperPosted Jan 11, 2013, 5:31 PM
{
PrintDocument printDoc = new PrintDocument();
PaperSource pkSource;
List listPaperSource = new List();
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < printDoc.PrinterSettings.PaperSources.Count; i++)
{
if (printDoc.PrinterSettings.PaperSources[i].SourceName == "test")
{
pkSource = printDoc.PrinterSettings.PaperSources[i];
}
listPaperSource.Add(printDoc.PrinterSettings.PaperSources[i]);
}
DropDownList1.DataSource = listPaperSource;
DropDownList1.DataTextField = "SourceName";
DropDownList1.DataValueField = "RawKind";
DropDownList1.SelectedValue = pkSource.ToString();
DropDownList1.DataBind();
}
if i use selectedvalue instead, i get no errors, only when i compile, it says:
{"Object reference not set to an instance of an object."}
does it help you ? :) is it because of a postback ?
can i in someway use a 2 dimensional list to hold sourcename and rawkind value ? and in that way get the rawkind that is corrosponding to the sourcename?
VulpesPosted Jan 11, 2013, 3:21 PM
comboPaperSource.SelectedValue = pkSource.RawKind.ToString();
That should cause the corresponding SourceName to be displayed in the DropDownList.
jesperPosted Jan 11, 2013, 2:56 PM
i dont need to display the rawkind to the user, but only the sourcename.. the rawkind number is only to change the papersource
VulpesPosted Jan 11, 2013, 2:52 PM
because the SelectedItem property of the DropDownList (the equivalent of the ComboBox in ASP.NET) is read-only.
You'd need to replace it with a line such as this:
comboPaperSource.SelectedValue = pkSource.SourceName;
However, notice that this code will only show the papersources in relation to a printer attached to the server - not the client, which can't be accessed directly for security reasons.
To do the same for the client you'd either need to use javascript or to ask the client to install a custom windows control (impossible, of course, unless the client machine is running Windows).
jesperPosted Jan 11, 2013, 1:49 PM
cus i cant figure it out /:
the code attached is the same as the accepted question in here :)
or maybe have an alternative solution :i
jesperPosted Jan 9, 2013, 4:33 AM
jesperPosted Dec 21, 2012, 5:04 AM
But is dosent work. you can see i use 2 displaynames, because the first is where i declare which printer i wanna have information from. and secondly there is no data in my combobox.
VulpesPosted Dec 20, 2012, 10:54 AM
1 DataSource property to an array or List of PaperSource objects,
2. DisplayMember property to "SourceName"; and
3. ValueMember property to "Kind" or "RawKind"
then, when the selection changes, you can just show the current SelectedValue in the MessageBox:
MessageBox.Show(comboBox1.SelectedValue.ToString());