Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Urgent -- Using ComboBox/TextBox, I want to convert into operator for Oracle Database [Plz Refer Detail]
 

Urgent -- Using ComboBox/TextBox, I want to convert into operator for Oracle Database [Plz Refer Detail]

Asalam o Aleikum and Hello,

I have a combo box with some text like:

Less than
Greater than
Equal to
Between
etc.

What I want is that when user click on this combo box to select text, the selected text is converted into operator and store in some global varaible for further use like

I select "Between" so i need this BETWEEN with AND to create query.
or select Less than so it will store this < operarot in string ?

Second is that I have two textBoxes which taked only numerics and decimal value.
How can i validate to both of tham and save into string ?
I have tried but it store only first number of lets say 2.5 so it will store only 2.

Allah Hafiz
Waquas s  Friday, September 07, 2007 9:17 AM

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

Rong-Chun Zhang  Tuesday, September 11, 2007 3:09 AM

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

Rong-Chun Zhang  Tuesday, September 11, 2007 3:09 AM
Thanks for that.


Waquas s  Tuesday, September 11, 2007 3:03 PM

You can use google to search for other answers

Custom Search

More Threads

• HTTP status 401: Access Denied
• need workaround to install on sql svr named instance
• TaskVision server source code?
• Genetic algorithms in Terrarium
• SQL Server Location
• ISA firewall issue
• Terrarium b1.0.21.281 available here...
• &#191;Why TaskVision does NOT use DataBinding?
• Problem with Concurrency Checking
• IssueVision.msi cannot find my SQL instance