?
Solved

Control array in MFC?

Posted on 2000-02-21
8
Medium Priority
?
696 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 40 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

765 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