|
|
Unfortunately not, but I work on now, if you have an A proposition, it will be appreciated.
think you
|
|
|
|
|
membre123 wrote: I work on now
Oookay... let us know how it goes.
|
|
|
|
|
Can you throw some more light on your problem ?
So that it is more clearer to understand and solve.....
Just give example of your derived class and what is lacking (your question)
so that it is clearly answered...
Jinal Desai - LIVE
|
|
|
|
|
|
Try to avoid Application.DoEvents... It's the wrong way to do things in .NET.
What you want is a BackgroundWorker. That's designed specifically for this situation. It goes something like this...
1) Create a BackgroundWorker for the "BusyOperation"
2) Create your progress dialog, and pass the worker to it, either in the constructor or via a property
3) The dialog hooks the RunWorkerCompleted event of the worker (Triggers when it's done), and optionally the progress changed event (See the MSDN documentation)
4) The dialog runs the background worker (Do not sit in a loop - Just exit the method). "BusyOperation" will automatically start asynchronously in a background thread.
5) When the RunWorkerCompleted event triggers, the dialog closes and returns control to the main form.
|
|
|
|
|
Hi Ian,
Thanks for your great advice.
I tried BackGroundWorker component also. However, I am getting same result - Form2 get hanged. Thereafter, I tried some stupid stuff and it worked.
I only copied form2_load code in public method (BuzyOperation) and called BuzyOperation() replacing it with frm2.show()
Form2 frm2;
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
frm2 = new Form2();
frm2.BuzyOperation();
}
After completing BuzyOperation(), below code will execute which will only show form2 with Job Done msg.
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
frm2.Show();
MessageBox.Show("Job done!");
}
I found the result as success, Now form2 is not getting hanged . I don't know what is going inside frm2.Show() (in our earlier scenerio), but i would like to know from you.
Pls. let me know.
Thanks in advance,
Chintan.
|
|
|
|
|
You're a little confused here... Don't worry, the threading is a little hard at first. There are two things to consider here...
1) The GUI thread has to stay unblocked, or your progress bar won't update
2) All controls HAVE to be created on the GUI thread, and only modified on that thread (Otherwise you get those crashes).
You're having problems because you're accessing the form inside the background worker... Can't do that. The point of the worker is that it works completely independently of the GUI, just letting you know when to update the progress.
So try creating the background worker from inside the Form2 constructor, then just call Form2's ShowDialog() from the main form.
public Form2()
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += BusyOperation;
bw.RunWorkerAsync();
}
Or something like that.
|
|
|
|
|
Check out this tip/trick:
http://www.codeproject.com/Tips/53695/Multiple-Subsequent-Main-Forms-in-Csharp-Apps.aspx[^]
I think it will help you do what you want to do.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi everyone, I am having problem with serialPort getting data. When I send data to the device the device gets it but I should get some data back, but in reality I don't get any data whatsoever. I have a serialPort SerialDataReceivedEventHandler but it does not get fire. I don't know why.
if any help please let me know. I have been trying it for few days almost.
serialPort1 = new SerialPort("COM3", 19200, Parity.None, 8, StopBits.One);<br />
serialPort1.ReadTimeout = 1000;<br />
serialPort1.Handshake = Handshake.None;<br />
serialPort1.ReceivedBytesThreshold = 1;<br />
if (serialPort1.IsOpen)<br />
serialPort1.Close();<br />
serialPort1.Open();<br />
byte[] request1 = new byte[] {(byte)'P', 4, 19, 6, (byte)'@'};<br />
serialPort1.Write(request1, 0, request1.Length);<br />
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived); <br />
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
this.Invoke(new EventHandler(DoUpdate));<br />
}<br />
private void DoUpdate(object s, EventArgs e)<br />
{<br />
while (serialPort1.BytesToRead > 0)<br />
{<br />
textBox1.Text = serialPort1.BytesToRead.ToString();<br />
}<br />
}
|
|
|
|
|
There are loads of possibilities, but the first thing I would do it move the event hook to before the SerialPort.Write so that i fthe response is quick enough, you don't miss it. I don;t think that will solve your problem, but it is a good idea anyway.
Now, open a terminal program of some kind, select COM3 and manually enter your data. Does the device respond, and can you read the data on the terminal? If not, check your wiring - RX and TX data, RTS, CTS, DTR, etc - whatever the device might need. This is assuming the device is actually connected to COM3 at all...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hello OriginalGriff, I check all of these and it works.
|
|
|
|
|
If all of that saya you are getting responses, then what kind of data are you expecting? Could it be that all you need to do is add a single '+' character to your code?
textBox1.Text += serialPort1.BytesToRead.ToString();
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi everyone, I got my solution by doing this. If anyone has the same problem you may try this.
serialPort1 = new SerialPort("COM3", 19200, Parity.None, 8, StopBits.One);<br />
serialPort1.ReadTimeout = 1000;<br />
serialPort1.Handshake = Handshake.None;<br />
serialPort1.ReceivedBytesThreshold = 1;<br />
this.serialPort1.DtrEnable = true;<br />
this.serialPort1.Handshake = System.IO.Ports.Handshake.RequestToSend;<br />
this.serialPort1.ParityReplace = (System.Byte)(0);<br />
<br />
if (!serialPort1.IsOpen)<br />
serialPort1.Open();<br />
this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);<br />
byte[] request1 = new byte[] { (byte)'P', 4, 40, (byte)'@' };<br />
serialPort1.Write(request1, 0, request1.Length);<br />
textBox1.Text = serialPort1.BytesToRead.ToString();<br />
this.serialPort1.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort1_ErrorReceived);
|
|
|
|
|
Hi,
please use PRE tags or the "code block" widget (not CODE tags or the "inline code" widget) to show multi-line code; it would preserve formatting, which makes things much more readable.
You can't touch your GUI Controls inside a DataReceived handler; this handler is asynchronous and runs on a ThreadPool thread, not on the main thread, so touching Controls there is forbidden. This[^] tells you more about it.
|
|
|
|
|
I want to create a datagrid inside a property grid,
As follows:
1. Property Name is same and it will have multiple dynamic rows. Each row will have 2 buttons. One to delete & one to fill data.
In datagrid it will be 3 columns, one for value & 2 for buttons.
Is it possible to create such a datagrid inside a property grid?
|
|
|
|
|
Sangeetha23 wrote: Is it possible to create such a datagrid inside a property grid?
Have you considered a UI Type Editor[^]? Or did you want to "embed" this datagrid into the PropertyGrid itself?
I are Troll
|
|
|
|
|
I gave him the same answer in Q&A. Hope he's got the message.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
It would be more fun when someone posted something creative
Would the question already be on SO or MSDN by now?
I are Troll
|
|
|
|
|
Thanks for your reply.
From msdn, i found UITypeEditor provides dropdwon & Modal buttons as uitypeeditoreditstyles. But I was not able to find the way to use both together.
Also the way to add rows dynamically is not clear.
|
|
|
|
|
Can you please provide suggestion to add multiple rows one after another.
Example Property will be "child Blocks". Values can be the multiple child blocks which user will browse one by one with a modal window. After each row getting filled with value one new row has to be added.
|
|
|
|
|
One possibility is to use a BindingSource[^] component as the DataSource for your DataGridView , then you can either have a Collection or DataSet as the DataSource of the BindingSource , or alternatively you can use the BindingSource as the Collection utilising its' Add, Insert, Remove and RemoveAt methods. Either way, all you need to do is programmatically add, delete or whatever, your new rows/child-blocks at the appropriate times. Because you will be using a BindingSource the changes to the collection should be automatically reflected in the DataGridView .
The BindingSource is a much under used component which is incredibly useful.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
C# Problem:
I have a string: " DH#2010-04-30-13:45:33"
Within this string a have certain charactes I want to use, and some I dont want to use:
2010 is my year,04 is my month,30 is my day,13 is my Hour,45 is my Minutes,33 is my Seconds
That string can come to me in many ways but this is the example for now.
I want to spesify the string to be used with another string, like a format guide.
This string is in my textboxbox and looks like this:
"___yyyy-MM-dd HH:mm:ss"
The first 3 underscores tells it to ignore the DH# part (3 Charactors)'
Then it needs to recognize the 2010 as yyyy, then 04 as MM etc.
The string can also be "#04#2010#30#13#45#33#
Then my format string will look like this: "_MM_yyyy_dd_HH_mm_ss_"
or
"DT04042010-134533"
Then my Format string will look like this: "__ddMMyyyy_HHmmss"
The format string I can specify, but the original string comes from a PLC in anyway it likes.
My format string specifies what each charactor in the string represents.
The underscore basicly tells the code to ignore the charactor in that place, in either:
yyyy,MM,dd or etc takes that digit and place it in the format I specify.
So I can use it to place it into the DateTime object.
Please help
|
|
|
|
|
I know of no standard way of specifying a wildcard for parsing DateTime strings, so you would have to remove the unwanted characters explicitly.
This is what you could do:
create a new format string and a new data string skipping the irrelevant characters (i.e. the '_' positions in the original format string), then pass the results to DateTime.TryParseExact
Example:
turn ___yyyy-MM-dd HH:mm:ss into yyyyMMddHHmmss
and DH#2010-04-30-13:45:33 into 20100430134533
[ADDED]
This approach will not work well all the time; IMO it does under these circumstances:
- all fields are numeric
- all fields have 2 digits, except year which needs 4.
[/ADDED]
|
|
|
|
|
Sorry but that won't work for DateTime.TryParse(). It needs the delimiters between date and time components.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|