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

VulpesRank #55 · 29.2K reputationPosted Dec 21, 2012, 5:44 AM EST
PrinterSettings ps = new PrinterSettings();
VulpesRank #55 · 29.2K reputationPosted Dec 20, 2012, 5:54 AM EST
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());
jesper89 reputationPosted Dec 21, 2012, 12:04 AM EST
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.
jesper89 reputationPosted Jan 8, 2013, 11:33 PM EST
jesper89 reputationPosted Jan 11, 2013, 8:49 AM EST
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
VulpesRank #55 · 29.2K reputationPosted Jan 11, 2013, 9:52 AM EST
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).
jesper89 reputationPosted Jan 11, 2013, 9:56 AM EST
i dont need to display the rawkind to the user, but only the sourcename.. the rawkind number is only to change the papersource
VulpesRank #55 · 29.2K reputationPosted Jan 11, 2013, 10:21 AM EST
comboPaperSource.SelectedValue = pkSource.RawKind.ToString();
That should cause the corresponding SourceName to be displayed in the DropDownList.
jesper89 reputationPosted Jan 11, 2013, 12:31 PM EST
{
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?
VulpesRank #55 · 29.2K reputationPosted Jan 11, 2013, 2:00 PM EST