I'm stuck on this one...I have a combobox that i've filled as shown below (code thinned out for simplicity):
[code]
// Load Material codes into combobox.
intID = somenumber; //ex: 123, 234
strItem = somestring; // ex: "white", "black"
Material item = new Material(intID, strItem);
cboMaterial.Items.Add(item);
// where Material is as shown below (code thinned out for simplicity):
private class Material
{
private int intMaterialID;
private string strMaterialCode;
public Material(int intID, string strItem)
{
intMaterialID = intID;
strMaterialCode = strItem;
}
public override string ToString()
{
return this.strMaterialCode;
}
}
[/code]
My question is that if later on in the code, if I know the value of "intID", how do I have the combobox display that selection?
While the following works, it's not what I need as I don't want to search for the strItem, but the intID.
[code]
cboMaterial.SelectedIndex = cboMaterial.FindStringExact("white")
[/code]
Loading
theLizardPosted Dec 24, 2009, 3:37 PM
Your material class should have a get and set for each of the members declared, in the same class file declare a second class to hold a lists of the material class
public class MaterialList :List
{
public record GetMaterialAt(int index)
{
return(this[index]);
}
public string GetMaterialStrCodeAt(int index)
{
return(this[index].strCode);
}
}
Material m = new Material();
m.member = "ljkglgljk";
m.memberId = 123;
MaterialList ML = new MaterialList();
ML.Add(m);
Combobox.Items.Add(m);
To get to the items of the material class in code
targetvar = ML.GetMaterialAt(Combobox.SelectedIndex).StrCode;
or
string s = r.GetMaterialAt(r.FindProductByStrMaterial("whatever"));
or if you return an int from the function
ComboBox.SelecetedIndex = r.FindProductById(intId);
have fun.