473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

group box

Hello,

1)I wanted to know if there is a way to determine the size of a group
box according to the number of radio buttons being added to it?

2)Is there a way to access to the radio buttons (in code) via the
group box control?

Thank U veru much!
Nov 16 '05 #1
5 11378
Hi Juli,

You can access any controls inside container controls like panels and
groupboxes.
Use the Controls property of the GroupBox to access its controls.

int n = 0;
foreach(Control c in MyGroupBox.Controls)
{
if(c is RadioButton)
n++;
}
MessageBox.Show("My GroupBox contains " + n + " RadioButtons.");

You can calculate the size based in the number of radiobuttons or access
the size of each control inside the GroupBox and add them together.

int h = 0;
int w = 0;
foreach(Control c in MyGroupBox.Controls)
{
if(c is RadioButton)
{
h += c.Size.Height;
w += c.Size.Width;
}
}

You can also set the Tag/Name property of the RadioButtons to identify
them further.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Hello,
I tried to do this:
foreach (Control c in this.groupBox1.Controls)
{
groupBox1.Size.Height=groupBox1.Size.Height+c.Heig ht;
}

but I keep getting compile error:
Cannot modify the return value of 'System.Windows.Forms.Control.Size'
because it is not a variable

How can I change this value?

Another question,
My controls inside the group box are radio buttons and I need to know
which one of them been selected,how do I do it via the group box?

Thanks a lot!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi,

You can't set the height or width individually, you need to set the full
size property.

foreach (Control c in this.groupBox1.Controls)
{
groupBox1.Size = new Size(groupBox1.Size.Width, groupBox1.Size.Height
+ c.Height);
}

As for your second question, you need to cast the control back to a
radiobutton.

foreach (Control c in this.groupBox1.Controls)
{
RadioButton rb = (RadioButton)c;
if(rb.Checked)
// do stuff
}

Note that if you have other controls than radiobuttons you will get an
exception.
In that case, test for a radiobutton using if(c is RadioButton).

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4
First of all ,Thanks! but I still have a problem with the size I did:
if(c is RadioButton)
{
groupBox2.Size = new Size(groupBox2.Size.Width,
groupBox2.Size.Height
+ c.Height);

}

but it becomes too huge ,maybe there need to be a casting or something ?
Thank you!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Without having tested it, I'm assuming the groupBox have an initial
default size that you need to ignore. Try setting the initial size to 0 or
perhaps even better, store the height of the RadioButtons only and set
GroupBox size at the end.
int n = 0;
foreach(Control c in groupBox2.Controls)
{
if(c is RadioButton)
n += c.Height;
}

groupBox2.Size = new Size(groupBox2.Size.Width, n);
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
2
by: BillD | last post by:
I'm trying to derive a schema from a base schema. I want to redefine a "group" from the base schema in my derived schema in order to add more options to the "choice" aggregate (see schema1.xsd...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
7
by: Darin | last post by:
I have a report that sub-totals on a group, then grand-totals at the report footer. If there's only one group, the sub-total and grand total are redundant, so I only want to show one of them. I...
1
by: David Horowitz | last post by:
Hi folks. I need to create a report that has a Group Header that pulls certain data from the Detail section. It's something like this: +--Report---------------------------------------- |...
7
by: Sameh Ahmed | last post by:
Hello there IsInrole gives ya the means to check if the current or impersonated user belongs to a specific windows role or group. is there a way to do the same without using ADSI to check if...
2
by: jon|k | last post by:
hi all-- i need to do a transformation that removes duplicates (among other things). to accomplish that, i'm trying to use for-each-group, but it doesn't work. i need to select for duplicates by...
3
by: Sebastian | last post by:
Hello all I have a report where I have two nested groups. I know there are only three standard options for running sum: None, Over Group and Over All. I have a MyTextBox in detail section where...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.