|
Elaine, I want to be able to define any sequence of characters as my signal for scanner input, where using accelerators would limit my options there. I also want to cater for EAN-8 as well as 13, so the TAB terminator is perfect, as it will raise the Leave event of my barcode edit box when any code, of any length, is read.
My next challenge is a nice to have, which is a global keyboard hook that ignores all key inputs between my scan signal and terminator. You get some really funny effects scanning when other Windows applications have focus. Windows pop in and out etc.
Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.
|
|
|
|
|
Hi Brady,
if you want to recognize a specific string (SEQ) the only thing you need
is a buffer of length SEQ.Length; since you need the string value for every
character you append, it is not useful to have a StringBuilder.
Hence use a string (say buf, initialized at "") and do:
buf=buf+e.KeyChar;
if (buf.Length>SEQ.Length) buf=buf.SubString(buf.Length-SEQ.Length, SEQ.Length);
if (buf.Equals(SEQ)) ...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc, it's easier to say,
if (buf.EndsWith(SEQ)) ...
I was doing that before, but I worried about the size of buf just using a string. If the user doing data capture without scanning, bu could get pretty big, and unless there is some internalisation magic I don't understand, every key press will create a new string . I use a StringBuilder so that I can remove the first character before appending the last. It seems to have acceptable performance.
Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.
|
|
|
|
|
Hi Brady,
Brady Kelly wrote: every key press will create a new string
So does your statement string buff = keyBuffer.ToString();
Brady Kelly wrote: I worried about the size of buf just using a string
My statement if (buf.Length>SEQ.Length) buf=buf.SubString(buf.Length-SEQ.Length, SEQ.Length);
limits the string length at all times (to 2 chars in case SEQ=x02x03).
If you don't want to do all the buffer stuff, there is one (slightly more complex)
alternative using a state machine, which basically remembers how many characters of SEQ
have been matched so far. So in one implementation it would use an int state;
and basically do:
if (e.KeyChar==SEQ[state]) state++; else state=0;
if (state==SEQ.Length) {
state=0;
... we got a match
}
the above code however is incorrect as soon as SEQ contains repeating characters though;
if you must cope with the general case it becomes much more complex...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Ooh, I really didn't read your first reply properly.
Thanks, I'll look into the state machine a bit later in the project, when I create a base form for all forms that use a scanner.
Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.
|
|
|
|
|
Anyone can point me to some Windows Form Free DataGrid-like control that can support Master / Detail View (a hirarchical sub-rows view, that is), if there is any? I've been searching google but couldn't find anything free :P.
Thanks.
|
|
|
|
|
Mr. Candyman wrote: I've been searching google
Interesting[^]
|
|
|
|
|
Thank you, but I was looking for a control to use in a Windows Application, and all I can see is for web app.
|
|
|
|
|
Mr. Candyman wrote: but I was looking for a control to use in a Windows Application
Interesting[^]
|
|
|
|
|
Thanks, but again I could'nt find anything useful. What I really need (if possible) is a control like the asp.net details-view (one single datagridview) but for a windows form and free. Some examples where interesting but mostly used 2 datagridviews, and I can do that myself
|
|
|
|
|
i am creating a customized messageBox to add the images and the icons that i need. I have a little problem is that the message and the lable that will hold it.
I need to make the lable to expand vertically as much as the text is, but not horizontally, how?
thanks for your help
abdelhameed81
|
|
|
|
|
If you set the height of the control, I'd imagine it wouldn't get any higher.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello to everybody,
I've got a problem with datagridview and generics, here's the piece of code :
<br />
dataGridView1.ReadOnly = false;<br />
List<Product> myProds = new List<Product>();<br />
<br />
myProds.Add(new Product("Prod 1", 1, 1));<br />
myProds.Add(new Product("Prod 2", 2, 2));<br />
myProds.Add(new Product("Prod 3", 3, 3));<br />
<br />
dataGridView1.DataSource = myProds;<br />
<br />
myProds.Add(new Product("Prod 99", 99, 99));<br />
on video I've 3 rows but in the datagrid.datasource I've 4 items.
Where do I do wrong?
Thanks in advance
Paolo Ponzano
|
|
|
|
|
As this is windows forms, there's no databind command, the grid is bound at the point that you set the data source. So, the objects you add after, are there, but the grid does not rebind every time you add an item.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
so what should I do?
Thanks
Paolo
|
|
|
|
|
Reset the datasource after you have added the new items.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
First of all, thanks to all of you for your answe, I've resolved it using BindingList<t> instead of List<t>, now I've a problem of cross-threading but I'm gonna take care of it!
Thanks again
Paolo
|
|
|
|
|
ok, now that the problem has been fixed we've another one that came out, and for this I need your help at all!!!
This is the main form event :
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
myWorker = new Worker();<br />
dataGridView1.ReadOnly = false;<br />
<br />
dataGridView1.DataSource = myWorker.myList;<br />
<br />
Thread myThread = new Thread(new ThreadStart(myWorker.DoWork));<br />
<br />
myThread.Start();<br />
}
The Worker class is this one :
public class Worker<br />
{<br />
public BindingList<Product> myList = new BindingList<Product>();<br />
<br />
public void DoWork()<br />
{<br />
Random r = new Random();<br />
for(int i=0; i<1000; i++)<br />
{<br />
myList.Add(new Product("Test",r.Next(),r.Next()));<br />
Thread.Sleep(1000);<br />
}<br />
}<br />
}<br />
At the myList.Add(...) I get an exception of type "Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on."
But this happen in a Business Object not in a Window's Control. I suppose this's because of the datagridview.Datasource property set, but how can I fix it?
Thanks in advance,
Bests
|
|
|
|
|
am writing an app that uses the .Net classes TCPClient and NetworkStream to read and write data between 2 machines. All works fine.
I have recently found a need to be able to send Http 1.1 with a SOAP message as the Http body. Currently i am using an XmlDocument to load and parse the SOAP data. However to do this i first have to read in the HTTP header, search for the beginning of the body and construct my own XmlDocument.
There must be a better way. I don't want to call a web service, i just want to send http with a soap body and receive the same.
I am looking for a means of loading in the NetworkStream into some kind of HTTP object to read the http stuff and also load the body into some simple Soap object that can be used to pull out/ set values.
Comments, Suggestions Welcomed.
Carl
|
|
|
|
|
|
That bad, huh?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hi,
I have one application that have one Mdi Form, and i would like to list all my open forms in a List View control.
Thanks.
Roberto
|
|
|
|
|
You will have to iterate through all of the form objects and if they are open, add them into the listbox.
Something like this:
foreach(Form childForm in MdiChildren) listBox1.Items.Add(childForm.Text);
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi,
It didn't work, but i think it would be something like that.
I'm gonna try more ways.
Thanks.
|
|
|
|
|
It should be something in that nature...My code was just a rough one, and it worked for me.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|