Solved

Control array in MFC?

Posted on 2000-02-21
8
677 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 171
Question regarding Copy/Paste 16 91
ShiftLeft challenge 21 76
matchUp  challenge 9 94
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now