Re: Databinding to a combo box: Newbie



Hi,
Suggest a class / struct that has place holders for m,n,o
Override the ToString function to return the 'look' that you want the
Combobox to display.
In the data retrieval create and fill a instance of the class for each
set of m,n,o
Add the class instances to the combo box.
The combobox will display the ToString output but the Selected item
will be an instance of your class so you can interact easily with m or
n or o.
HTH
Bob

public struct stTuple
{
public string m;
public string n;
public string o;
public override string ToString()
{
return "M " + m + " N " + n + " O " + o;
}
}

private void Form1_Load(object sender, EventArgs e)
{
stTuple a = new stTuple();
a.m = "mvalue";
a.n = "nvalue";
a.o = "ovalue";
stTuple b = new stTuple();
b.m = "mbvalue";
b.n = "nbvalue";
b.o = "obvalue";
this.comboBox1.Items.Add(a);
this.comboBox1.Items.Add(b);


}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs
e)
{
stTuple s =(stTuple)(this.comboBox1.SelectedItem);
MessageBox.Show("Selected o value is " + s.o);
}

On 26 Mar 2007 14:39:59 -0700, "weird0" <amirediwan@xxxxxxxxx> wrote:

I want to bind data to combo box from a db that returns something
like three tuples with the content m,n,o of the same field. How can i
do that?

Can i just store the result in an array of string and add
sequentially m....n....o . Is their anyway?

Let me know how can i do it. Refer to some good link to learn to bind
combo box to db as to what i
want to do.
.



Relevant Pages

  • Re: ToString Debug vs Display strategies & preferences
    ... IFormattable implementation as well as ToString() override. ... public string FirstName ... public string ToString(string fmt, IFormatProvider fp) ... How about generalized debugging ToString stratagies? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: property inference
    ... public string FirstName ... public override string ToString() ... if you do this type of inference there's no access to the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: this.toString
    ... > I am a java beginner. ... > keyword makes an implicit call to Objects toString method as in the ... could have picked public String converThisObjectToAString() but I guess they ...
    (comp.lang.java.programmer)
  • Re: DirectorySearcher.FindAll() causes Unspecified Error in C# but not in VB.NET
    ... >public string getEmail ... which you try to cast by calling .ToString- but you're calling that ... can't just call a .ToString() on either. ... VB.NET probably shields you from those programming errors by some ...
    (microsoft.public.dotnet.languages.csharp)