Checkbox and Radio Button Programming on GUI

2652
49
Jump to solution
02-20-2014 10:33 AM
MichelleCouden
Occasional Contributor
Am I on the right path here with my checkboxes and radio button programming. I have about three different checkboxes and a few radio button that I need to use in a If then statement. Unless, there is a simplier way of calling a layer using them...

private void checkBox1_Checked Changed(object sender, EventArgs e)

      If (checkboxstate.checked == true) Then
           If radioAtr.Enabled Then openFileDialog.InitialDirectory = "K:\"......

All help is extremely appreciated. Thanks!
0 Kudos
1 Solution

Accepted Solutions
LeoDonahue
Occasional Contributor III
Stations are considered to be one of the following?  ATR, AVC, BC, LTPP, Manual and Toll Road?

Now that I see what you are trying to do, using Radio Buttons for the State, Austin, San Antonio, etc. makes more sense because you can only have one of those selected at a time, right?

And I would use checkboxes for: ATR, AVC, BC, LTPP, Manual and Toll Road options, because you said you can have multiple of those checked at the same time.

Now you don't have to repeat all of the: ATR, AVC, BC, LTPP, Manual and Toll Road checkboxes on different tabs.

View solution in original post

49 Replies
KevinYanuk
Occasional Contributor
Am I on the right path here with my checkboxes and radio button programming. I have about three different checkboxes and a few radio button that I need to use in a If then statement. Unless, there is a simplier way of calling a layer using them...

private void checkBox1_Checked Changed(object sender, EventArgs e)

      If (checkboxstate.checked == true) Then
           If radioAtr.Enabled Then openFileDialog.InitialDirectory = "K:\"......

All help is extremely appreciated. Thanks!



Looks like you're on the right path.  Just as a tip in the future, use the "
" tags (the # symbol in the post editor) to post you code.


Also, for boolean checking, you don't need == true.  i.e.:


// checked
if (myCheckBox.Checked) 
{
    // some code
}


// not checked
if (!myCheckbox.Checked)
{
    // some code
}
0 Kudos
LeoDonahue
Occasional Contributor III

private void checkBox1_Checked Changed(object sender, EventArgs e)

      If (checkboxstate.checked == true) Then
           If radioAtr.Enabled Then openFileDialog.InitialDirectory = "K:\"......


Hi Michelle,

If I understand what you have posted, you want this logic to run when the checkbox is being checked or being unchecked?  You have this logic in the Checked Changed method, is that what you wanted?  If it is being unchecked, why do you want to check another boolean value to see if it is enabled to decide whether to open a file dialog?

Maybe could you expand on what you want to do?  Maybe with a screenshot of your GUI?
0 Kudos
MichelleCouden1
Occasional Contributor III
Sorry Leo, I should have explained my idea for this program. Yes, I am using both checked box and radio buttons. When the box is checked and then they have checked a radio button a certain shapefile will open. For Example, they check State and then check the radio button to Manual the manual shapefile will open. I just thought I could use all checkboxes and no radio buttons that would probably be easier. Thanks for your help!
0 Kudos
LeoDonahue
Occasional Contributor III
Hmm.. Ok.

What is the difference between checking State and Manual?  Is Manual related to State?

Yould could use all checkboxes for this project. 

You could have a really long "if" statement that checks every checkbox to see if it is checked and add the corresponding layer, or you can make it more elegant/complex and maybe use a control array or perhaps add/remove values to an array list or something and then iterate over the array list to add those layers to your map.
0 Kudos
LeoDonahue
Occasional Contributor III
I guess what I'm saying is...

If the State checkbox is checked, the additional status of a radio button only gives you two options.. Manual or not Manual?

It seems like overkill to say:  If the State checkbox is checked, do you want to load the Manual layer or the other layer? Why not just give the user the option to load one or the other, why relate those choices to whether a State checkbox is checked or not checked?
0 Kudos
MichelleCouden1
Occasional Contributor III
Yes, you are right. I knew it was going to be a really long If statement. Yes, State is related to Manual. They are maps of traffic count stations.  For Example, the user would pick state (for the state of texas) and then check manual (manual is a type of station), then that shapefile of the state with manual stations pops up. So, I agree with you all checkboxes are the way to go. Let me try to fix code and I'll send it to you to check for me. Thanks again.
0 Kudos
LeoDonahue
Occasional Contributor III
As I recall, you are building a string value with these checkbox options right?  I think it was based on your directory layout if I remember correctly.

Didn't one of the other people in the forum give you some samples that worked?
0 Kudos
MichelleCouden1
Occasional Contributor III
Yes, I have a code for the radio button. I was going to rewrite it to make sure I get the concept of the ArcObjects language to use for the check boxes.
 If checkboxstate = true Then

If checkboxManual = true Then openFiledialog.InitialDirectory = "K:\......



Just making sure on the language I am not familiar with ArcOBject laguage i.e. openFileDialog and checkbox=true and so on...
0 Kudos
LeoDonahue
Occasional Contributor III
Just so I understand, why do you want to double check something in order to load a shapefile?

Why do two conditions have to be true:  checkboxstate and checkboxManual  in order to load a shapefile?

Why not just call a checkbox:  checkboxStateManual ?
0 Kudos