hi there,
i have a combo box in my windows form. combo box has 6 items in it e.g connect first, disconnect first, connect second, disconnect second,.....
when i click on connect first...certain checkboxes get checked...when i click on diconnect first..certain checkboxes get unchecked as well. But, I want to add the messagebox..for example if first is connected and user clicks on connect second without disconnecting first...then i want to have message up pop up .. how can i do that..
i tried to add code in the selectedvalue, updatedtext etc. but didn't work ...
any feedback is appreciated!
Vimal KandasamyPosted Apr 24, 2009, 6:00 AM
It will be better if you check those checkbox in its property.Because Exe should be loaded perfectly.Its very important.
we will change those checkbox checked status in some other events.
I checked your exe by commenting those lines in write() method.Its nice.I just tried to check all events from combobox.
It will be great ,if you provide Perfect Error info to user and allow him to retry.
All the Best.
ShaniPosted Apr 24, 2009, 2:18 AM
i sort of looked at it
and yeah in the constructor i try to check 4 checkboxes. i want to have them checked when i run the exe. If i check them from checkbox property then they are always checked.
that is the only reason i initialize them in the checkbox.
if you want to run the exe..you can simple just comment out the label_rety to until end of 2nd exception try / catch block from dll and you wont get problem seeing whats happening and all..
other than that i willl look at your changes and reply to you accordingly...
thanks alot Vimal...you have been a great help.. :)
Vimal KandasamyPosted Apr 24, 2009, 1:46 AM
I sent report about your project.Check it in your mail.
All because of exception.you didn't handle exception well.
and you call those methods in constructor.
so only when you start your exe if board is not powered.It throws error and terminates it.
and Connecting your dll under radiobutton is nothing,just call dll methods under its event
i hope i fix all your problems.
please check and do necessary changes.and reply me.
i m waiting......................................................
ShaniPosted Apr 23, 2009, 9:36 AM
hey Vimal,
1. Yup, I call methods from dll in my exe.
2. I call the methods in checkboxes, comboboxes events.
3. I guess the dll runs at exe runtime...i reference it using namespace
and yeah i emailed you the prg
Vimal KandasamyPosted Apr 22, 2009, 4:05 AM
Some questions
How will you communicate with dll from your exe.Whether you call methods of dll from exe?...
i want to know ,where you call those methods in exe?... In the initialize time or some other place.
now you start your exe,on which time[or line] it communicates your board via dll?
I want to know about communication between your dll and exe.That will solve the problems i think so.
ShaniPosted Apr 21, 2009, 2:17 PM
I guess goto will do :) its for minor purpose anyways. But, i remember reading that you can use goto statement for going down the code but not up. I should be fine with it.
About confirm dialog with retry option, I don't think i can use it since its a dll class library and it doesn't support windows.forms namespace in it.
I was wondering..can you pass me your email address..i can send you the dll and maybe if you have time you can skim through with the whole class and suggest me something.. I am still not able to find solution for starting dll with a button.
Vimal KandasamyPosted Apr 21, 2009, 12:59 AM
you can use goto loop for retry 3 times automatically... after that you can show your TimeOutException to user.
somethong like below..
int Errcount = 0;
Label1:
try
{
_serialPort.Open();
_serialPort.Write(x, 0, 5);
for (int i = 0; i <= 4; i++)
{
y[i] = (byte)_serialPort.ReadByte();
// Console.WriteLine(y[i]);
}
}
catch (TimeoutException)
{
_serialPort.Close();
Errcount++;
if (Errcount < 3)
{
goto Label1;
}
else
throw new ArgumentException("No response from the board. Please ensure board is powered up properly");
}
If you want to do it manaully like show a confirm dialog to user.if user press retry then we try again..
if like that means you have to put everything in a function.and call it while user press retry.try and tel me
ShaniPosted Apr 21, 2009, 12:19 AM
I will let you know if i could find any solution to it..
Vimal KandasamyPosted Apr 20, 2009, 4:11 AM
I don't know how to separate dll from windows exe...But i know, it is possible.Because I saw this in many software.so please try to find, how to do this?.
All the Best.
ShaniPosted Apr 18, 2009, 2:41 AM
i exactly did what you just wrote..just checked if file exits, read from it and delete it in the end
so i had that stuff in the radio button 'connect serial port' but i think after showing the msg..since there was a problem in the dll i would have to re-start the exe
but i just didn't think before.. i will try this first thing in the morning on monday when i get to workk
when i build the windows form as exe ..dll gets shipped with it too.. so maybe i can just build the form alone as exe and dont have the dll in the exe set up.. that way when i would run the set up ..i wouldn't have dll ..so no errors should error and then run it form radio button if possible..
would you know how though?
i will try it still..
have you build windows form as an exe and have dll with it which is also visual studio class library project..
as per referencing we say usign mydll and add it in reference..
and so if i wanna have it in a button..is there a specific way for it. couldn't really find much on internet
have a nice weekend Vimal :)
Vimal KandasamyPosted Apr 18, 2009, 12:44 AM
one small suggestion
Instead of checking date time, check whether file exist or not.[you simply delete file after reading and check whether file exists or not in the beginning]
Don't allow your dll to control the execution of your exe... whenever a problem occurred in dll it should write it into log file...it should not affect exe.
and it is better to check the log file,[whether it exists or not] whenever a user trying to communicate to board...and interface must inform the user about the problem.
ShaniPosted Apr 17, 2009, 1:02 AM
Yup, I will try it when i get to work... I logged the exception in a txt file..
then in the form load event i check if the file exists and if the updated time is equal to datetime.now and then show the dialog box to power up the board.
is this the right way of checking the file and throwing dialog box.. or you suggest something else..
e.g. form_load(this, e); doesn't work :S for some reason.. i can call click event methods like that with no problem..
thanks, running the dll from connect serial port is good but i dont know how i can run the dll from radio button..because to reference my dll and to use functions from there..
all i do is..
using mydll;
add the dll to reference
and thats about it..
so i have no idea how i can just run the dll from radio button.. because dll(just a class library visual studio project) right...so it should be possible..
i looked at some stuff like import dll, or somethiing like that over the internet..didn't make sense..
thanks Vimal :)
Vimal KandasamyPosted Apr 17, 2009, 12:49 AM
Sorry for asking questions again
1.throw new ArgumentException("No response from the board. Please ensure board is powered up properly");
this will through an exception na?
where you catch this exception ?...
and in try catch block ,you wrote code only for TimeoutException...
you please add another catch block like
catch(Exception Ee)
{
// Pass Exception Occurred info to Exe or write it in file
}
this will catch all exception
and in exe you please show that passed msg via MessageBox to user...or please redirect them to log file to know about Error...
i m not sure, but i guess "your exe has encountered a problem and needs to close...." occurred because you didn't handle Exception well.you throw Exception again in catch block...but i don't know where you catch it and handle...
For my applications, If i didn't put my code under try-catch blocks.In run time
it will show "an Error Occurred in your program........" with Debug,Continue Quit buttons...
ShaniPosted Apr 16, 2009, 11:04 AM
Answering your questions Vimal..
1. Yup, I am handling the timeoutexception when the board is not powered up from dll as you can see from above code.
2. When board is not powered up and I run the exe .. I get "your exe has encountered a problem but needs to close" and not the other message. I am not sure why is that though.
3. I am not sure if I can..
from your reply, what i gather is: i get the "your exe has encountered a problem and needs to close" because i am not catching some exception... is that it.. ? i am sort of confused at this..
on the other hand..can't i just run the dll and do everything on the exe if i click on radio button.."connect serial port" that kind of sound better and on disconnecting i am no longer communicating with the board..
it's just kind of neat..because maybe someoen just checking the itnerface and have the exe open..not actually communicating with the board.. you know what i mean...
in the last couple of lines what you said.. i wouldn't mind doing that also
e.g. having stuff under checkboxes, or buttons where i call methods from dll to check if board is powered or not and show message. i dont wanna exit the program ..i wanna handle the exception and continue with it
Vimal KandasamyPosted Apr 16, 2009, 1:57 AM
still we have a chance.
I have some questions
1.Are you Handling the Time out Exception which is thrown by dll if board is not powered?.
2.When your board is not powered,and if you execute your exe,then what it shows?
"No response from the board. Please ensure board is powered up properly"
OR
"your exe has encountered a problem and needs to close...."
3.Can you pass any info from dll to your form?...
If yes then simply pass the Exception occurred info to exe...
and show the confirm dialog box..
If No then write that info into a file[like log file]... and check that file in any form events and throw above dialog
If you can refer[runs] your dll after a checkbox checked or button click then do that... and if board is not powered then
show confirm dialog like above...
if you cant refer [runs] like that then try to do that in form load or some other events..
It will be better ,if you able to control dll reference or execution under any events or components
basically, if you catch an Exception and Handles it.then your exe will show it to user and continue its process..
if you doesn't catch & handles.then it will show
"your exe has encountered a problem and needs to close...."
and terminate your program.
ShaniPosted Apr 15, 2009, 1:27 PM
right..
Vimal KandasamyPosted Apr 15, 2009, 1:03 AM
Ex: When you access a printer application it will show msg searching for printer............
and if its not powered then it will show
Please connect printer first then click ok
[OK] [Cancel]
if you click ok again it search for printer...
when you click cancel it simply terminate the application.
I want to know one thing?..
Where you call your dll methods to check whether board is connected or not...
I suggest you to call those method on form loading event [call at the end]...
If device is not connected then you can throw confirm dialog...
ShaniPosted Apr 14, 2009, 11:40 AM
i am not sure how it could be done :( may be you can show.
all the methods are in the dll and i just merely use windows form exe to call those methods. Do i need to add something in the initialize component constructor so it runs the exe without any error and then show the confirm dialog and clicking ok it runs the dll or whichever way is possible
Vimal KandasamyPosted Apr 14, 2009, 12:17 AM
It is Nice idea...
Initially board is disconnected and when user click connect it runs dll and connect your board with serial port.
But what i felt in this is..
In the Exe loading you simply check your board via dll.. If it is not powered then you throw a Confirm dialog...
" Please Connect your device First. then click ok"
[OK] [Cancel]
if user clicks OK, dll will check again and if its not connected then again it throw same msg...
If user click Cancel
you simply terminate application
OR
show your form with a msg...Device disconnected..
and
Give option to Connect...
Is it Ok?..
ShaniPosted Apr 13, 2009, 3:55 PM
I used another approach and it worked fine. I wanted to know if this is possible... I have try/catch in the dll that checks if the serialport is connected to the board or not.
I am only able to run the exe when my board is powered up..if not then i get the message 'your exe has encountered a problem and needs to close....'
i am guessing its because when you run the exe it runs the dll..
so i added radio buttons in my form : connect serial port, disconnect serial port..
is it possible for me to run the exe even if my board is not powered up .. basically what i am thinking of doing is.. when i run the exe (i should no longer see the message your exe has encountered a problem and needs to close' i should by default be on disconnect serial port option and when i choose connect serial port then it runs the dll and i am able to do stuff...
i reference my dll like using dllname; in my form program and add it ...so if i remove it from theere and add if under connect serial port radio button ..would it work or something else i need to do
Vimal KandasamyPosted Apr 8, 2009, 9:27 AM
For Windows Form,if form size is 400,300 then you plz Set Maximumsize property of form as 800,300.. This will increase the width...
then you add code
this.WindowState = FormWindowState.Maximized in a button click event..
and also set MaximizeBox=false to prevent maximize it manually...
then in Checkbox problem,
What i got from your explanation is,
Combobox2 selection change some checkboxes[checked by combobox1] from 1 to 0... so you want to perform OR operation between both selections...
Am i Correct?...
but you can perform OR operation between results instead of performing it with selected values..
ex combobox1 results-> 10101010 [1->true and 0->false for checkbox.checked ]
combobox2 results-> 01100101
then Result muse be 11101111
for OR operation see the below example..treat your 1 as true..and 0 as false..
bool[] b = { true, false, true, false };
bool[] c = { false, true, false, false };
bool[] d = new bool[4];
for (int i = 0; i < 4; i++)
d[i] = b[i] | c[i];
d contain [true,true,true,false]....
by using this array you can check your checkboxes...
and you can do this after Results of combobox2 selection retrieved from dll.... you must store checkboxes status [ which are checked by combobox1] in an array.and store new results[by combobox2] in another array...
before apply new result you simply perform OR operation as shown above.
then apply resulted array for checkbox status..
I hope it will help you...
ShaniPosted Apr 8, 2009, 1:36 AM
about showing the whole form ..i wanna set the width and height from right to left...i wanna show right half sort of form first and then clicking on button show the rest...what do i need to do for that?
i am also stuck with this thing..and cant think of way of doing it...i will explain it under
I am getting 32 bit integer from my dll for different functions and then add it with 0x01, 0x02 and on wards and depending on what is my 32 bit value i am checking my checkboxes...
its working great seperately for each combobox item.. but there is also times when i want to have 2 items selected from 2 different combobox selection.
the way my 32 bit value (return from dll functions) is that if i want to have certain checkboxes checked then i give assign it a value of 1 and all the other checkboxes to 0..
so whats happening is that when i select an item from combobox1..it checks lets say 8 checkboxes.. now when i select another iterm from second combobox...it checks 8 checkboxes..but since both e.g 0x50080c5 and 0x500ae046 (just random numbers so you can picture ) go into my one method and gets anded with 0x01, 0x02 one by one coming from right to left and depending on that checks the checkboxes.. since both have different zeros and ones associated to them and because of that when i selected the item from combobox1 it checks some checkboxes and when i selected an item from combobox2 it checks some but the onez that were checked form combobox1 gets unchecked since they are assigned a zero.
i have a solution to this..when i get the item from combobox1 i check the checkboxes and if someone selects an iterm form combobox2 then i can do an or operation with these two items 32 bit integer and the result i can add and check the checkboxes....
i just dont know how to do this.. i dont know if i can do it in the selectindex method or whatnot..
i hope i tried to explain this properly.. let me know if you think of something or need clarity somewhere..
thanks Vimal :)
Vimal KandasamyPosted Apr 4, 2009, 3:08 AM
we cant avoid checkbox_checkchanged event i think so...
But we can use a flag to avoid executing...
like below...
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if(flag==0)
{
//code needs to be executed
}
}
if flag=1 then it wont execute fully...
simply set this flag=1 while you set checkbox from dll to avoid checkchanged event...
and to check a checkbox from dll... you simply pass your Boolean info to form then set checkbox status....
you can call a method or set property of form to pass value...
for my applications, i use constructor to pass such info to form and in form loading, i will use those info and set my settings according to that...
try it...
ShaniPosted Apr 4, 2009, 2:25 AM
When I used the idea connect remove items, disconnect add items and for messagebox pop up i actually set the selectedindex to -1 and it works pretty well.:)
about the checkboxes..i am basically communicating with the dll and getting hex from there and then AND it with the hex i get and depending on that i check or uncheck the box..
I call different functions from dll in for my checkbox checkchanged event. I still want to have the stuff there..
I want to know if it is possible to just check the checkbox and not go into the checkchanged event. :)
Vimal KandasamyPosted Apr 4, 2009, 12:36 AM
I got one more idea about combo box... to clear combo box selection, we can use combobox1.SelectedIndex=-1
and to show rest form try the following...
Initially set Form Properties like below
FormBorderStyle =FixedToolWindow
[in order to avoid manual resize]
MaximumSize=width,height
[to show rest of form,set size of full form here...
ex: if initially 300,400 then in maximum size set 600,800]
WindowState=Normal
and when user clicks Advanced settings button...
Maximize your window using the code
this.WindowState = FormWindowState.Maximized;
this will show you the rest of form
To verify the checkbox status
use
if(checkbox1.Checked)
{
//code
}
to set check box status assign a value
like
checkbox1.Checked=true;
try all...
ShaniPosted Apr 3, 2009, 10:35 AM
Thanks for the help.
I used the idea you gave me before.. when you connect you remove everything and disconnecting brings it back.
Is it possible for me to only show half the form and when i click on advanced settings i get the rest half of it appreared...?
also, is it possible for me to check the checkboxes without even going into checkchanged event.
Vimal KandasamyPosted Mar 30, 2009, 12:35 AM
add 1st element [index=0] of combobox
as "select"...
then in combobox_selectedindexchanged event...
add a condition i.e
if(combobox.selectedindex!=0)
{
//all code which are executed for selectedindexchanged event
}
then
after show the error msg "disconnect first"...
you can set combobox.selectedindex=0 instead of setting combobox.selecteditem=sel
[sel=>our previous value]
so now combobox has its initial value "select"...
event executed again but its terminate quickly because we check index in the first line
i.e
if(combobox.selectedindex!=0)
{
}
so no problem...
I think it will help you....
ShaniPosted Mar 28, 2009, 6:51 PM
thanks for your help so far..yeah please let me know if you can find the solution for the previous one. I tried many things but didn't have any success.
Thanks
Vimal KandasamyPosted Mar 28, 2009, 3:18 AM
i tried lot ways for that but nothing works fine... sorry....
i have one more idea...
but you have to decide whether its useful or not..
the idea is
initially we have
connect first
connect second
connect third
as items in combo box..
if user choose connect first...
then all other items should be removed
and combobox contain only one item
i.e disconnect first...
after user select disconnect first... we
will show
the initial menu again.
if user select second then we remove all and add only disconnect second...
same for connect third also...
Is it ok?..
but still i am trying to resolve that problem for you.,.. if i find solution for that then immediately i will inform you...
ShaniPosted Mar 27, 2009, 11:03 AM
since index changes..it goes back to the very first line of the event and do the whole thign again.. coz the stuff in under selectindexchanged.
and combobox.selectedtext doesn't work
Vimal KandasamyPosted Mar 27, 2009, 12:38 AM
try
comboBox1.SelectedText = sel;
[Sel contain previous Item ]
ShaniPosted Mar 26, 2009, 1:38 PM
working just fine:)
now one more thing.. when i show the msg..please disconnect first with the sel string and everything..after when i press okay i want the first connected item to be highlighted and not the second one..
so i want the focus on the first connected item on combobox..
I am trying some stuff..it would be nice to have your idea in it
Vimal KandasamyPosted Mar 26, 2009, 6:11 AM
this is also a simple one.
you simply store the selected Item in a String variable like
String sel=combobox1.SelectedItem...
this statement should be present after Flag var set to 1...
do not put in the beginning[it will get varied for each selection].
so when next selection checking
in the msg display
"Please Disconnect First!" + sel
[sel contain what you selected earlier...]
once again i remind you that you must put that statement where you set Flag=1[i.e selection accepted] not in the beginning...
ShaniPosted Mar 25, 2009, 4:17 PM
Thanks for the idea. I did it how you said and it works fine.
Now, the problem is when i give the message ' Please Disconnect first' I also want to say disconnect what first.
e.g if Connect first is connected and without disconnecting i try to connect second... I should get a message ..Please diconnect first.
MessageBox.Show("Please Disconnect First!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);I was thinking if I could concatenate what was previously selected that would be great.
I tried doing ..."Please Disconnect First!" + Combobox1.SelectedItem + ""
but that gives the item that i recently selected.. I want to get one before that and i want to get the previous one ..(the one was connected before but never disconnect)
so lets say if previous one was .."Connect B Mode" then I want to have Connect Char removed and only show please Disconnect B Mode first.
if you get what i mean..I dont know how to do it..
please help!
Vimal KandasamyPosted Mar 25, 2009, 3:31 AM
you can set a flag [ just set an integer variable to 1] when connection first was selected.and set it to 0 when connection first was disconnected.
and when user trying to connect second, you simply check out flag.if it set to 1 then you restrict user to select connect second by setting combobox1.Selectedindex=0 or other index value and show a msg box.
for the above,you can add code in combobox's Selected IndexChanged event.