c# - How do I change Folderlocation with radio buttons in a groupbox? -
i have these groupboxes
i want open specific folderlocation depending on radiobuttons checked in groupboxes.
so let's option 1 , option b open desktop , option 2 , option folder on desktop.
i know how run single radiobutton have difficulties in how make work 2 groupboxes.
if have shown code better understand terminologies. case use nested for
, if
like
//some path ever want string[] paths = { environment.getfolderpath(environment.specialfolder.desktop), environment.getfolderpath(environment.specialfolder.applicationdata), "c:\\"}; string[] folders = { "somefolder", "anyfolder", "yesthisfolder" }; string calcfolderpath=""; for(int i=0;i<=1;i++) //this group { for(int j=0;j<=2;j++) //this option / radio button { //you have check if group option checked or not if(group[i].option[j].checked) //this might not work { if(i==0) { calcfolderpath = path[j]; } else { calcfolderpath = calcfolderpath + folders[j]; } } } }
this idea. program might not work because not been tested.
this program depicts first outer loop check run 2 times check number of groups have. inner loop number of radio button have in groups. checking if group's option button checked or not. if checked checking if group1 taking path , if group2 taking folder name.
hope helps
edit
after comment somthing
string path = ""; string foldersname = ""; string completepath = ""; private void optionbutton1_checkedchanged(object sender, eventargs e) { if (optionbuttona.checked == true) { path = "c:\\users\\z003cypv\\desktop"; } completepath = calccompletepath(); } private void optionbutton2_checkedchanged(object sender, eventargs e) { if (optionbuttona.checked == true) { path = "c:\\users\\z003cypv\\documents"; } completepath = calccompletepath(); } private void optionbutton3_checkedchanged(object sender, eventargs e) { if (optionbuttona.checked == true) { path = "c:\\users\\z003cypv\\pictures"; } completepath = calccompletepath(); }
then folders
private void optionbuttona_checkedchanged(object sender, eventargs e) { if (optionbuttona.checked == true) { foldersname = "somename"; } completepath = calccompletepath(); } private void optionbuttonb_checkedchanged(object sender, eventargs e) { if (optionbuttona.checked == true) { foldersname = "namefolder"; } completepath = calccompletepath(); } private void optionbuttonc_checkedchanged(object sender, eventargs e) { if (optionbuttona.checked == true) { foldersname = "somefoldername"; } completepath = calccompletepath(); } public string calccompletepath(); { return path + foldersname; }
but inefficient way of doing things. still prefer first option.
Comments
Post a Comment