Hi Allah Hafiz,
For your first question, you can create a table to store the text and the operator, and bind ComboBox to this table. You can get the operator using ComboBox.SelectedValue.
For your second question, you can handle the TextBox.Validating event and check if the data is in correct format. Check my sample below.
Code Snippet
CBO
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void Form6_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("text");
dt.Columns.Add("operator");
dt.Rows.Add("less than", "<");
dt.Rows.Add("Greater than", ">");
dt.Rows.Add("Equal to", "=");
dt.Rows.Add("Between", "BETWEEN ? ANF ?");
dt.AcceptChanges();
this.comboBox1.DisplayMember = "text";
this.comboBox1.ValueMember = "operator";
this.comboBox1.DataSource = dt;
//validating text in textboxes
this.textBox1.Validating += new CancelEventHandler(textBox_Validating);
this.textBox2.Validating += new CancelEventHandler(textBox_Validating);
}
void textBox_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
try
{
decimal d = decimal.Parse(tb.Text);
}
catch
{
MessageBox.Show("Data type error!");
e.Cancel = true;
}
}
}
Thanks. Rong-Chun Zhang |