Solved

Control array in MFC?

Posted on 2000-02-21
8
685 Views
Last Modified: 2013-11-20
Hello,
I am novice in MFC programming. I use VC++ 5.0. I have 70 radio buttons in one group. Now when i press OK, i want to know which radio button is checked. Is there any method to know that? same way i have edit boxes in one group and i want to know which edit box is empty.

Thanks,
Namrata
0
Comment
Question by:namrata
8 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2542139
Hi,

Give the Ids of the radio buttons and edit boxes carefully and continuosly. 100 - 170 for radio buttons.

Then in OnOk() do

for(int Index = 100; Index < 170; Index++)
{
if(((CButton *)GetDlgItem(Index)->GetCheck() == 1)
{
//Yes, that is Ur checked button
break;
}
}

Then follow the similar thing for edit boxes, and in OnOk() do
for(int Index = 200; Index < 270; Index++)
{
CString Text;
Text.Empty();
((CEdit *)GetDlgItem(Index)->GetWindowText(Text);
if(Text.IsEmpty())
{
//Yes, that is Ur empty edit box
}
}

Those Ids U can open the resource.h and change them.
try it out.
VinExpert
0
 
LVL 1

Accepted Solution

by:
mahno earned 10 total points
ID: 2542148
To khow, which radio button is checked, U need to associate variable with first button in group:

right mouse button click -> Class Wizard -> Member variables -> Add variable

Add new variable:

m_Radio
Value
int

In code:

UpdateData(FALSE); //Update m_Radio
switch (m_Radio) {
  case 0: //...Selected 1st button
  case 1; //...Selected 2nd button
//...etc
}

For edit boxes:

CString szStr;

GetDlgItem(IDC_EDIT1)->GetWindowText(szStr);

if (szStr.IsEmpty()) {
  //Edit is empty
}

Hope thats helps,
  mahno
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2542380
Hi namrata,

you can also use GetNextDlgGroupItem() to step through all controls of the group...

ZOPPO
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:namrata
ID: 2544453
Hi mahno,
I used UpdateData(TRUE) and its working. But it doesn't work with UpdateData(FALSE). Am i doing something wrong? Also, with this method, if i add more radio buttons in that group, then i will only have to change resource.h (for continuous IDs) and not rest of the program. is that right?

not checked edit box part yet. sorry for the delay.

Namrata
0
 
LVL 1

Expert Comment

by:mahno
ID: 2545075
Hi namrata,

Of course, UpdateData(TRUE); It's my mistake :( U don't need to change resource.h file (radio ID's have no any effect to). U need to set propierty "Group" on first check and set right tab order.

mahno
0
 

Author Comment

by:namrata
ID: 2545175
Hi mahno,

thanks for the help. Radio button part works now. but can i get control ID from the member variable value? e.g. if my member variable value is 0, how do i know that its control ID is 500?

also am trying edit box part. As i wrote, i have group of edit box. Edit box contain strings so will member variable work this time? i have a group of 10 edit box and want to know which edit box(es) is(are) empty. should i process as GetNextDlgGroupItem() to step through all controls of the group or is there any other way?

thanks again, sorry for the trouble
Namrata
0
 
LVL 1

Expert Comment

by:mahno
ID: 2545585
Hi namrata,

>thanks for the help. Radio button part
>works now. but can i get control ID
>from the member variable value? e.g.
>if my member variable value is 0, how
>do i know that its control ID is 500?

Why U want to know ID? If U want to change radio button U can do this by following way:

m_Radio = 3;//new value
UpdateData(FALSE); //Now FALSE :-)

About Edit boxes:
Yes, U can use GetNextDlgGroupItem()

brgs,
  mahno


0
 

Author Comment

by:namrata
ID: 2545620
Thanks mahno,

I know i have asked some silly questions. Thanks for the patience. Here are your points.

Thanks to Vinexpert and Zoppo also for the help.

Namrata
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
List out all word 7 317
zeroMAx challenge 20 111
Modbus - whats the maximum I can store in one register? 4 80
JQuery serialize and unserialize 8 135
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question