Click here to Skip to main content
15,923,376 members
Home / Discussions / C#
   

C#

 
QuestionInsert Fails W/Unique Constraint Pin
rich_wenger2-Sep-05 9:09
rich_wenger2-Sep-05 9:09 
AnswerRe: Insert Fails W/Unique Constraint Pin
Mohamad Al Husseiny2-Sep-05 14:53
Mohamad Al Husseiny2-Sep-05 14:53 
QuestionRegular Expression Pin
Derick Cyril Thomas2-Sep-05 8:17
Derick Cyril Thomas2-Sep-05 8:17 
AnswerRe: Regular Expression Pin
Guffa2-Sep-05 8:32
Guffa2-Sep-05 8:32 
AnswerRe: Regular Expression Pin
Alomgir Miah2-Sep-05 9:18
Alomgir Miah2-Sep-05 9:18 
QuestionDataGridView has no CaptionText or Title property Pin
billoo2-Sep-05 8:00
billoo2-Sep-05 8:00 
Questionget text from ie address bar Pin
qsosoq20002-Sep-05 7:33
qsosoq20002-Sep-05 7:33 
Questionoverride ToString() for Combobox Pin
PHDENG812-Sep-05 6:53
PHDENG812-Sep-05 6:53 
I cant seem to get this code to work. I need populate a combobox with items that have separate values. For instance: When the user selects "item" within the combobox the "value" associated with that item will be displayed in a textbox.

private void Form1_Load(object sender, System.EventArgs e)
{
ComboBox c = new ComboBox();
c.Items.Add(new MyItem("Item", "Value"));
textBox1.Text = ((MyItem)c.SelectedItem).Content;

}


class MyItem
{

private string item; // String to show in the ComboBox
private string val; // String to show in the TextBox

public MyItem(string i, string v)
{
item = n;
val = v;
}

public override string ToString()
{
return item;
}

public string Content
{
get
{
return val;
}
}

}

It doesn't seem to like this bit of code:

textBox1.Text = ((MyItem)c.SelectedItem).Content;

Error: Object Reference not set to an instance of an object

Any help would be appreciated.
Thanks

-- modified at 12:54 Friday 2nd September, 2005
AnswerRe: override ToString() for Combobox Pin
Guffa2-Sep-05 7:11
Guffa2-Sep-05 7:11 
GeneralRe: override ToString() for Combobox Pin
PHDENG812-Sep-05 7:20
PHDENG812-Sep-05 7:20 
QuestionComboBox Mayhem Frustration. Pin
rich_wenger2-Sep-05 5:02
rich_wenger2-Sep-05 5:02 
AnswerRe: ComboBox Mayhem Frustration. Pin
Michael Potter2-Sep-05 5:33
Michael Potter2-Sep-05 5:33 
GeneralRe: ComboBox Mayhem Frustration. Pin
rich_wenger2-Sep-05 5:47
rich_wenger2-Sep-05 5:47 
GeneralRe: ComboBox Mayhem Frustration. Pin
Michael Potter2-Sep-05 6:09
Michael Potter2-Sep-05 6:09 
Questionwildmat in C# Pin
Mridang Agarwalla2-Sep-05 4:19
Mridang Agarwalla2-Sep-05 4:19 
AnswerRe: wildmat in C# Pin
Judah Gabriel Himango2-Sep-05 4:41
sponsorJudah Gabriel Himango2-Sep-05 4:41 
Questionapplication path in class library Pin
Mridang Agarwalla2-Sep-05 4:16
Mridang Agarwalla2-Sep-05 4:16 
AnswerRe: application path in class library Pin
Judah Gabriel Himango2-Sep-05 4:43
sponsorJudah Gabriel Himango2-Sep-05 4:43 
AnswerRe: application path in class library Pin
miah alom2-Sep-05 5:13
miah alom2-Sep-05 5:13 
GeneralRe: application path in class library Pin
miah alom2-Sep-05 5:15
miah alom2-Sep-05 5:15 
Questionremoving vbcr and vbtab at the end of a string Pin
Mridang Agarwalla2-Sep-05 4:07
Mridang Agarwalla2-Sep-05 4:07 
AnswerRe: removing vbcr and vbtab at the end of a string Pin
Mohamad Al Husseiny2-Sep-05 4:47
Mohamad Al Husseiny2-Sep-05 4:47 
AnswerRe: removing vbcr and vbtab at the end of a string Pin
miah alom2-Sep-05 4:48
miah alom2-Sep-05 4:48 
AnswerRe: removing vbcr and vbtab at the end of a string Pin
Judah Gabriel Himango2-Sep-05 4:52
sponsorJudah Gabriel Himango2-Sep-05 4:52 
AnswerRe: removing vbcr and vbtab at the end of a string Pin
Guffa2-Sep-05 5:23
Guffa2-Sep-05 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.