first of all i'm using microsoft visual C# 2010 express
this is about a form
i don't want to dynamically generate a form
but for some textBoxes to dynamically display the result of me messing around with the controls
so i have a listBox
http://msdn.microsof...ms.listbox.aspx
filled up with n quantity of double numbers
and i want to simply know what has the user selected from the list and display it on a textBox
i used this SelectedIndexChanged event and GetSelected method like this
private void SelectedIndexChanged(object sender, EventArgs e)
{
c = double.Parse(k.GetSelected(k.SelectedIndex).ToString());
W.Text = c.ToString();
}
}
this compiles, but i'm not quite sure it makes sense:
k is my listBox object, it contains an array of strings
so k.SelectedIndex is the index of whatever element of the strings array the user chose
i'm giving it to the k.GetSelected so i get the element, and them i'm changing it to string so i can make it a double...?
anyways i have my global double with a value i can somewhere else mess with
but in order to display it i have to change it back to string so the textBox recognizes it?
i hope i got this right
but anyways, this won't do a thing if i run it, because i know i have to place an eventHandler somewhere...
the point is where? the visual express makes a lot of files
so i have one "file" called Form1.Designer.cs where there's all the stuff about the form
namespace BS
{
partial class BS
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BattSelect));
//[... lots of labels, boxes and stuff in here ...]
this.k = new System.Windows.Forms.ListBox();
this.W = new System.Windows.Forms.TextBox();
//[... lots of those labels, boxes and stuff parameters in here ...]
// kVA
//
this.k.FormattingEnabled = true;
this.k.Items.AddRange(new object[] {
"1",
"2.7",
"3.5",
"6",
"10.3",
"15.8",
"20.4",
"30.6",
"40.5",
"50.4",
"60.3",
"80.7"});
this.k.Location = new System.Drawing.Point(117, 3);
this.k.Name = "k";
this.k.Size = new System.Drawing.Size(53, 17);
this.k.TabIndex = 8;
//
// W
//
this.W.Location = new System.Drawing.Point(117, 135);
this.W.Name = "W";
this.W.Size = new System.Drawing.Size(59, 20);
this.W.TabIndex = 10;
this.W.Text = "-";
//[... things about the layout...]
#endregion
//[... declarations ...]
private System.Windows.Forms.ListBox k;
private System.Windows.Forms.TextBox W;
}
}
and that's it
so according to this site
http://csharpdotnetf...t-handling.html
i believe i need to place
EventHandler(this.k.SelectedIndexChanged); //with or without () at the end is the same
in this file, next to all other stuff about k, but if i do that, this happens
Error 1 The name 'EventHandler' does not exist in the current context Error 2 The event 'System.Windows.Forms.ListBox.SelectedIndexChanged' can only appear on the left hand side of += or -=
the first error makes me think i need to add some headers to the file
which ones and to which of all my files, i have no idea
the second error...
i found this about someone having more or less the same problem somewhere, but i lost the link, sorry
"To reference static fields you need to use the class name not the name of an instance.
e.g. int i = Pay.Click; .
The error you are getting is because ppay.Click refers to the Click event that can only be set."
and that info just leaves me the same as before. i don't understand what that means
at any case that there is not the way to link the k listbox with the event handler, but then how do i do that properly?
please, help me out
thanks

New Topic/Question
Reply



MultiQuote




|