Link to home
Start Free TrialLog in
Avatar of namrata
namrata

asked on

Control array in MFC?

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
Avatar of Vinayak Kumbar
Vinayak Kumbar

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
ASKER CERTIFIED SOLUTION
Avatar of mahno
mahno

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zoppo
Hi namrata,

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

ZOPPO
Avatar of namrata

ASKER

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
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
Avatar of namrata

ASKER

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
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


Avatar of namrata

ASKER

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