Solved

Control array in MFC?

Posted on 2000-02-21
8
692 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

695 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