Class 1
public static class DatabaseDeformacijaArmature
{
public static NovaDeformacijaArmature[] GetAllDeformacijaCelika()
{
return new NovaDeformacijaArmature[]
{
new NovaDeformacijaArmature
{
DeformacijaArmature = "20 %",
epsilonCelika = 20.0
},
new NovaDeformacijaArmature
{
DeformacijaArmature = "10 %",
epsilonCelika = 10.0
},
new NovaDeformacijaArmature
{
DeformacijaArmature = "5 %",
epsilonCelika = 5.0
}
};
}
Class 2
var deformacijaCelika = DatabaseDeformacijaArmature.GetAllDeformacijaCelika();
deformacijaCelikaComboBox.Items.AddRange(deformacijaCelika);
private void deformacijaCelikaComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
NovaDeformacijaArmature selectedDeformacija = deformacijaCelikaComboBox.SelectedItem as NovaDeformacijaArmature;
if
}
How to set if DeformacijaArmature = "20 %" is picked then do something... then again if 10%, do same "something" as for 20%. Same thing for 5%
that something will be written below.. thank you in advance
Something like this?
private void deformacijaCelikaComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
double selected = ((NovaDeformacijaArmature)deformacijaCelikaComboBox.SelectedItem).epsilonCelika;
if (selected == 20.0)
{
//do stuff
}
else if (selected == 10.0)
{
//do stuff
}
else if (selected == 5.0)
{
//do stuff
}
}
Alternative use the class:
public class NovaDeformacijaArmature
{
public double epsilonCelika { get; set; }
public override string ToString() //This will be used when rendered by the combobox
{
return string.Format("{0:N0} %", epsilonCelika);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.