Click here to Skip to main content
15,902,911 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
Wheels01226-Jan-09 1:32
Wheels01226-Jan-09 1:32 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
Wheels01228-Jan-09 2:05
Wheels01228-Jan-09 2:05 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
DaveyM6928-Jan-09 7:08
professionalDaveyM6928-Jan-09 7:08 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
Wheels01228-Jan-09 8:37
Wheels01228-Jan-09 8:37 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
DaveyM6928-Jan-09 9:41
professionalDaveyM6928-Jan-09 9:41 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
DaveyM6930-Jan-09 9:28
professionalDaveyM6930-Jan-09 9:28 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
Wheels01230-Jan-09 9:31
Wheels01230-Jan-09 9:31 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
Wheels0124-Feb-09 2:47
Wheels0124-Feb-09 2:47 
Hi Dave.

Finding it challenging to get it working.

I have a form with a comboBox and the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
const string constrLetterColumn = "Letter";
const string constrDeptID = "DeptID";
const string constrDeptColumn = "Department";
const string constrExpandColumn = "Expansion";

DAL d = new DAL();
DataSet ds;
DataTable dt;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
}

void InitializeCombo()
{
// Constructing data set in code, obviously this would come from your DAL
DataSet ds = new DataSet();
ds.Tables.Add();
ds.Tables[0].Columns.Add("ID");
ds.Tables[0].Columns.Add("Display");
ds.Tables[0].Rows.Add(new object[] { 1, "One" });
ds.Tables[0].Rows.Add(new object[] { 2, "Two" });
ds.Tables[0].Rows.Add(new object[] { 3, "Three" });
ds.Tables[0].Rows.Add(new object[] { 4, "Four" });
ds.Tables[0].Rows.Add(new object[] { 5, "Five" });
// the next three lines fill your combo and set the members
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "Display";
comboBox1.ValueMember = "ID";
// subscribe to SelectedIndexChanged event
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
}
}


Where am I going wrong?

WHEELS
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
Wheels0124-Feb-09 8:08
Wheels0124-Feb-09 8:08 
GeneralRe: C# Populate Multi column (2) combobox with existing dataset (hide record #) Pin
DaveyM694-Feb-09 13:16
professionalDaveyM694-Feb-09 13:16 
QuestionSplash Screen / Init question Pin
EliottA23-Jan-09 8:50
EliottA23-Jan-09 8:50 
AnswerRe: Splash Screen / Init question Pin
DaveyM6923-Jan-09 9:10
professionalDaveyM6923-Jan-09 9:10 
AnswerRe: Splash Screen / Init question Pin
User 665823-Jan-09 10:01
User 665823-Jan-09 10:01 
QuestionError: RegularExpression can't be found [modified] Pin
u060509423-Jan-09 8:35
u060509423-Jan-09 8:35 
AnswerRe: Error: RegularExpression can't be found Pin
DaveyM6923-Jan-09 8:41
professionalDaveyM6923-Jan-09 8:41 
GeneralRe: Error: RegularExpression can't be found Pin
u060509423-Jan-09 8:43
u060509423-Jan-09 8:43 
GeneralRe: Error: RegularExpression can't be found Pin
DaveyM6923-Jan-09 8:51
professionalDaveyM6923-Jan-09 8:51 
GeneralRe: Error: RegularExpression can't be found Pin
u060509423-Jan-09 8:57
u060509423-Jan-09 8:57 
GeneralRe: Error: RegularExpression can't be found Pin
DaveyM6923-Jan-09 9:06
professionalDaveyM6923-Jan-09 9:06 
GeneralRe: Error: RegularExpression can't be found Pin
PIEBALDconsult23-Jan-09 9:43
mvePIEBALDconsult23-Jan-09 9:43 
GeneralRe: Error: RegularExpression can't be found Pin
DaveyM6923-Jan-09 10:05
professionalDaveyM6923-Jan-09 10:05 
GeneralRe: Error: RegularExpression can't be found Pin
u060509423-Jan-09 16:53
u060509423-Jan-09 16:53 
GeneralRe: Error: RegularExpression can't be found Pin
User 665823-Jan-09 9:48
User 665823-Jan-09 9:48 
GeneralRe: Error: RegularExpression can't be found Pin
PIEBALDconsult23-Jan-09 12:42
mvePIEBALDconsult23-Jan-09 12:42 
GeneralRe: Error: RegularExpression can't be found Pin
u060509423-Jan-09 16:46
u060509423-Jan-09 16:46 

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.