Text Box
The following code in c# allows only integers or decimal in a text box
private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsControl(e.KeyChar)) return;
e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != '.';
}
The following c# code auto completes the text box with following properties
{
if (Char.IsControl(e.KeyChar)) return;
e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != '.';
}
1.Suggest
2.Append
3.None
4.SuggestAppend
Note:The auto complete string is taken from data table
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
DataTable dt = dataSet.Tables["TableName"];
foreach (DataRow item in dt.Rows)
{
collection.Add(item[3].ToString());
}
if (textBox != null)
{
textBox.MaskBox.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox.MaskBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox.MaskBox.AutoCompleteCustomSource = collection;
}
For further question please mail: brainstormiert@gmail.comforeach (DataRow item in dt.Rows)
{
collection.Add(item[3].ToString());
}
if (textBox != null)
{
textBox.MaskBox.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox.MaskBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox.MaskBox.AutoCompleteCustomSource = collection;
}