Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How to use droplist and switch
How to use droplist and switch [message #1751] Fri, 17 March 2006 17:32 Go to next message
mechatronic is currently offline  mechatronic
Messages: 10
Registered: December 2005
Location: Viet Nam
Promising Member

Hi everybody.
I'm a newbie in U++ and I have a project that communicate to other device via rs232 or LPT. I want to place a switch (ratio box - i think so Very Happy ), or droplist (combo box - sure). When an user choose one, program will set a variant (ex: user choose com1, so port = com1), but I don't know what to do. No example and reference programs about this.
Help me, please Razz
Re: How to use droplist and switch [message #1764 is a reply to message #1751] Sat, 18 March 2006 08:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mechatronic wrote on Fri, 17 March 2006 11:32

Hi everybody.
I'm a newbie in U++ and I have a project that communicate to other device via rs232 or LPT. I want to place a switch (ratio box - i think so Very Happy ), or droplist (combo box - sure). When an user choose one, program will set a variant (ex: user choose com1, so port = com1), but I don't know what to do. No example and reference programs about this.
Help me, please Razz


Just add "key"-"display value" pairs to your DropList. Its value will be the "key".

DropList dl;
dl.Add(1, "One");
dl.Add(2, "Two");
dl <<= 1;
..........
PromptOK(AsString(~dl));


Mirek
icon8.gif  Re: How to use droplist and switch [message #10808 is a reply to message #1751] Tue, 31 July 2007 04:47 Go to previous messageGo to next message
bonami is currently offline  bonami
Messages: 186
Registered: June 2007
Location: Beijing
Experienced Member
707dev1, winxp
how to add items to a switch? thank you.
i've got a switch in .lay, which can be assigned only one value. i try to add more in my main function with all methods as follows, but never achieved.

char s[] = "UDP TCP";
s[3]='\n';
comm_type.EnableCase(1);
comm_type.EnableCase(2);
comm_type.EnableCase(3);
comm_type.SetLabel(s);
comm_type.SetLabel(2, "TCP");
comm_type.Add(1,"UDP");
comm_type.Add(2,"TCP");
comm_type.EnableCase(1);
comm_type.EnableCase(2);
comm_type.EnableCase(3);
Re: How to use droplist and switch [message #10812 is a reply to message #10808] Tue, 31 July 2007 11:19 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
comm_type.SetLabel("UDP\nTCP");

or
comm_type.Add("UDP").Add("TCP");

or
comm_type.Add(0, "UDP").Add(1, "TCP");

Will all work.

I would guess that you haven't made the Switch ctrl large enough in the Layout Designer (it does not resize automatically) and so you cannot see the other opptions.

James.
Re: How to use droplist and switch [message #10815 is a reply to message #10808] Tue, 31 July 2007 12:14 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
bonami wrote on Tue, 31 July 2007 03:47


i've got a switch in .lay, which can be assigned only one value. i try to add more in my main function with all methods as follows, but never achieved.


If I understand you correctly, you want to add more switch values with the layout designer. You can achieve that with "Set label" by adding more lines (preess Enter).

Alternatively, you can copy this layout (I suppose you know how to use Ctrl_T):
LAYOUT(SwitchButtonLay, 400, 200)
	ITEM(Switch, swt_1, SetLabel(t_("&Opt1\nO&pt2")).LeftPosZ(28, 104).TopPosZ(12, 17))
END_LAYOUT


Then you can change vertical-horizontal layout simply by resizing with a mouse (changing ratio)
Re: How to use droplist and switch [message #10829 is a reply to message #10812] Wed, 01 August 2007 07:46 Go to previous messageGo to next message
bonami is currently offline  bonami
Messages: 186
Registered: June 2007
Location: Beijing
Experienced Member
mrjt wrote on Tue, 31 July 2007 17:19

comm_type.SetLabel("UDP\nTCP");

or
comm_type.Add("UDP").Add("TCP");

or
comm_type.Add(0, "UDP").Add(1, "TCP");

Will all work.

I would guess that you haven't made the Switch ctrl large enough in the Layout Designer (it does not resize automatically) and so you cannot see the other opptions.

James.

as i posted, i have used all these methods and none works for me. i tried again exactly using your Add... and failed. my layout is large enough to hold an elephant.

solution: put Add... in a function called after window class' constructor. i put Add... in topwindow's subclass' constructor then nothing works as i said and i cannot even stop there to debug. but if i put it elsewhere and call it after construction, it succeeds. this really puzzles me.

FUDAMIN, i've succeeded modifying .lay using TheIDE. this works.

thank you both anyway.

[Updated on: Wed, 01 August 2007 07:50]

Report message to a moderator

Re: How to use droplist and switch [message #10857 is a reply to message #10829] Wed, 01 August 2007 18:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Do not waste the time (ours, yours...).

In cases like this, zip the package and post here (unless it is larger than 100KB or so... Smile. Much faster for everybody to find out what is wrong...

Mirek
Re: How to use droplist and switch [message #10875 is a reply to message #10857] Thu, 02 August 2007 03:06 Go to previous messageGo to next message
bonami is currently offline  bonami
Messages: 186
Registered: June 2007
Location: Beijing
Experienced Member
main.cpp line 38. you can replace the Add() with anything like Add(,) setlabel(). nothing works.
instead, if you create a function to be called before ezcw.Run() (the last line of the cpp), and call Add() or anything there, it works.
  • Attachment: ezcomm.rar
    (Size: 4.99KB, Downloaded 265 times)
Re: How to use droplist and switch [message #10881 is a reply to message #1751] Thu, 02 August 2007 13:34 Go to previous messageGo to next message
dmcgeoch is currently offline  dmcgeoch
Messages: 52
Registered: November 2006
Location: New Jersey
Member
Hello,

I was looking at the code that you posted and noticed two possible issues. The first is the size of the switch control. If you expand the size of the control in the layout designer, the expanded area is available, but not visible to the user. The second is an issue that I have noticed previously, if you define any of the fields in the layout designer, you cannot modify those fields on the fly.

Attached is a copy of your code with the changes in place. I removed the contents of the functions that were not relevent to the issue.

Dave
  • Attachment: ezcomm.rar
    (Size: 4.34KB, Downloaded 267 times)
icon6.gif  Re: How to use droplist and switch [message #10897 is a reply to message #10881] Fri, 03 August 2007 04:19 Go to previous messageGo to next message
bonami is currently offline  bonami
Messages: 186
Registered: June 2007
Location: Beijing
Experienced Member
as i did afterwards, you changed .lay, too. this is the best way.
the key is the second problem you mentioned. i suppose the control is partialy initialized after the TopWindow so that you cannot set it in TopWindow's constructor.
as for the first one, i changed .lay, so i see the size is OK and did not change it back for the code to describe this question, i.e., it is not a problem.

further more, when i try to get selected value, if i directly call GetData(), it won't work, since .lay does not generate default values, even values as indexes or labels.
void ezcommwin::Butt_out()
{
...
comm_type.Set(0,0, "uu"); // this works
comm_type.Set(1,1);  //this does not work
type = comm_type.GetData(); //only now can we get the value


after all, maybe it is a good idea not to use .lay for switches

[Updated on: Fri, 03 August 2007 11:48]

Report message to a moderator

Re: How to use droplist and switch [message #10955 is a reply to message #10897] Tue, 07 August 2007 14:53 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
The problem is that you are calling CtrlLayout AFTER you have configured the controls. Move the CtrlLayout call to the fist line in the contructor and it works fine (you may also need to make the switch bigger).

CtrlLayout will override all changes you have made to the form, so you should always call it first (unless you're using it to reset a window).

James.
icon14.gif  Re: How to use droplist and switch [message #10966 is a reply to message #10955] Wed, 08 August 2007 08:57 Go to previous message
bonami is currently offline  bonami
Messages: 186
Registered: June 2007
Location: Beijing
Experienced Member
mrjt wrote on Tue, 07 August 2007 20:53

The problem is that you are calling CtrlLayout AFTER you have configured the controls. Move the CtrlLayout call to the fist line in the contructor and it works fine (you may also need to make the switch bigger).

CtrlLayout will override all changes you have made to the form, so you should always call it first (unless you're using it to reset a window).

James.

U R so exactly right
Previous Topic: howto force evaluation after <CR>
Next Topic: "ScrollArea"...
Goto Forum:
  


Current Time: Fri Mar 29 15:23:27 CET 2024

Total time taken to generate the page: 0.01814 seconds