|
Hello,
jason_mf wrote: But it is noneffective.
YEs, sorry you also have to handle KeyPress!
But what I would recommend is inheriting your own NumericTextBox from TextBox.
public class NumericTextBox : System.Windows.Forms.TextBox
{
And override OnKeyPressed and OnKeyDown:
bool keydownHandled;
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.D0:
case Keys.D1:
case Keys.D2:
case Keys.D3:
case Keys.D4:
case Keys.D5:
case Keys.D6:
case Keys.D7:
case Keys.D8:
case Keys.D9:
case Keys.NumPad0:
case Keys.NumPad1:
case Keys.NumPad2:
case Keys.NumPad3:
case Keys.NumPad4:
case Keys.NumPad5:
case Keys.NumPad6:
case Keys.NumPad7:
case Keys.NumPad8:
case Keys.NumPad9:
case Keys.Enter:
break;
default:
e.Handled = true;
break;
}
keydownHandled = e.Handled;
base.OnKeyDown (e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = keydownHandled;
base.OnKeyPress (e);
}
For the ENTER Key you can do the handling of KeyDown directly on the Form.
Hope it helps!
P.S.: Don't forget to care about "copy/paste"
All the best,
Martin
|
|
|
|
|
Hello,
An other way to validate the KeyPress for numeric input is:
const string validinput = "1234567890";
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (validinput.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
}
base.OnKeyPress (e);
}
All the best,
Martin
|
|
|
|
|
Here's my solution. Any comments are welcomed.
static bool isIISContainsCert() {
try {
DirectoryEntry W3C = new DirectoryEntry("IIS://Localhost/W3SVC");
foreach(DirectoryEntry entry in W3C.Children) {
PropertyCollection props = entry.Properties;
if( props["KeyType"].Value.ToString() == "IIsWebServer"
&& props["SSLCertHash"].Value != null ) {
return true;
}
}
} catch (Exception e) {
GTools.Logger.FileLog(e.ToString());
}
return false;
}
|
|
|
|
|
I have an arraylist that contains objects who themselves contain multiple properties. I would like to know is there are faster way than using a for loop to search through an arraylist to find the object whose certain property matches what I am looking for. An example of what I am currently doing is listed below.
for(int p = 0; p < SupplierItemDataStore.Count; p++)
{
if(stock.Code == ((XMLDefs.SupplierItem.SupplierItem)SupplierItemDataStore[p]).StockCode)
{
{
//Do stuff here
}
}
}
where stock is the object that is passed in and SupplierItemDataStore contains over 31,000 items.
|
|
|
|
|
I don't think that there will be more faster way.
<br />
foreach(XMLDefs.SupplierItem.SupplierItem sItem in SupplierItemDataStore){<br />
if(stock.Code = sItem.StockCode){<br />
}<br />
}<br />
There are a lot of C# gurus in our forum.. let's see what they say..
|
|
|
|
|
If you put the data in a HashTable with the stock code as key, you can locate the item very quickly.
If you use framework 2.0 you would use a Dictionary instead of a HashTable.
---
single minded; short sighted; long gone;
|
|
|
|
|
>>If you put the data in a HashTable with the stock code as key, you can locate the item very quickly.
Yeah. Great Idea. Thanks..
|
|
|
|
|
Thanks for your help guys. The hash table is the way I'm going to have to go as the application I'm developing is on Framework 1.1 so I can't use a Dictionary.
|
|
|
|
|
Hello friends,
i have one problem, i have one table control in that table control i took 5 radiobuttons. below table control i have 2 text boxes.
totally 33 qns , upto 31 i want radio button after 31 i want textboxes inplace of radion buttons.
please give me one idea, how can i adjust this design.
please urgent......................
srinivas
|
|
|
|
|
Still the online test/quiz?
Place your radio buttons and text boxes on the form as you would usually do. Set the textboxes' Visible property to false.
When you reach the 32nd question, set the radio buttons' Visible property to true and the textboxes' Visible property to true.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
hi all,
i have a list view and lisviewitems in this listview , now when i right click on any lisviewitem it getting selected , i don't want to select it with right click , i just want to select itwith left click.How can i cancel the event when it's right click coz there is no cancel in MouseEventArgs.
please help me.
thanx.
Praveen Sharma
|
|
|
|
|
in my C# program,i input "at" in a textBox,then the program send "at" to serialport,but when i click receive button,the message I receive from serial port is the same as what I input,namely "at",not "ok",why?who can answer my question?How I solve this problem and get the right response "ok" from serial port?
next is my code:
public partial class Form1 : Form
{
private SerialPort sp = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
sp = new SerialPort("COM1");
sp.ReadTimeout = 5000;
sp.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
sp.Write(textBox1.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
/*string text=null;
char[] buffer = new char[10];
sp.Read(buffer,0,6);
for (int i = 0; i < buffer.Length; i++)
{
text += buffer[i];
}
textBox2.Text = text;*/
/*string text = null;
char t = (char)sp.ReadChar();
text+=t.ToString();
while (true)
{
t = (char)sp.ReadChar();
if (t == '\0') break;
else text += t.ToString();
}
textBox2.Text = text;*/
string text = null;
byte[] t = new byte[20];
char[] c = new char[20];
sp.Read(t, 0, t.Length);
sp.Read(t, 0, t.Length);
c = Encoding.ASCII.GetChars(t);
int i;
for (i = 0; i < c.Length; i++)
{
if (c[i] == 'O' || c[i] == 'K')
text += c[i].ToString();
}
textBox2.Text = text;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
|
|
|
|
|
|
if the end result is not what you want it is wise to look at the intermediate data,
in your case log the bytes that the serial port returns to you (I would use HEX numbers).
If they are exactly what you have sent, then either your target device is echoing them,
or you have an unintended connection between TxD and RxD (transmit data and receive data)
on your serial cable.
|
|
|
|
|
Hello,
how can i display the hex values for each byte of a sting in a richtextbox?
thanks!
|
|
|
|
|
Hello,
roiter wrote: for each byte of a sting
I don't understand this!
But maybe you are searching for this:
string HexText= String.Format("{0:X}", value);
Hope it helps!
All the best,
Martin
|
|
|
|
|
thank you! i will try it later.
I am knew in C#. in C there is no datatype string, you can define a byte array and use it as a string. So each byte is manipulateable by indexing.
|
|
|
|
|
Wellcome
All the best,
Martin
|
|
|
|
|
roiter wrote: use it as a string. So each byte is manipulateable by indexing
in C# the indexer (myString[x]) returns the 16-bit character at position x.
|
|
|
|
|
In .NET the characters are not bytes, they are unicode characters. A string is basically an array of char . A char is a 16 bit value, so you can cast it to a short or an int to get the character code.
Example:
foreach (char c in someString) {
int code = (int)c;
Console.Write(code.ToString("x4"));
Console.Write(" ");
}
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello EveryBody,
I had two combo box (combo box1, combo box2)
I had populated the combox1 using dataset (having values in display member and value member)
I want to pupulate combo box2 on the selectedindexChangeEvent but
I am getting System.Data.DataRowView on comboBox1.selectedvalue.tostring();
I am unable to understand why it is returning this value.
And outside this event it is giving right value.
working on c# (windows application)
Regards,
rahul saini
|
|
|
|
|
It would be more helpful if you could put some code also...
Just call me Valy...
|
|
|
|
|
Hi Valy,
Here is the code for populating the combo box1
string sqlQuery = "select * from category ";
SqlConnection objConnection = new SqlConnection(objFunctions.strConn);
objConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, objConnection);
DataSet ds = new DataSet();
adapter.Fill(ds);
DataTable objDataTable = ds.Tables[0];
cmb_category.DataSource = objDataTable;
cmb_category.DisplayMember = "categoryName";
cmb_category.ValueMember = "categoryId";
objConnection.Close();
AND on selectedIndexChangeEvent
I m populating combo box using comboBox1.selectedValue
but it is returning System.Data.DataRowView
Regards,
rahul saini
|
|
|
|
|
hi
instead of using combobox1.selectedvalue
you have to use
combobox1.selectedindex.tostring()
Nisar Inamdar.
|
|
|
|
|
Hi Nisar,
It is giving the index value but i want the selectedItemValue for populating
comboBox2 with help of the value i had to retrieve value from database
Regards,
rahul saini
|
|
|
|