locked
how to string array for selected .c,.h and other files? RRS feed

  • Question

  • Hi All,

    I have a save fuctoin which will save the user selection fron the GUI to a text file. I want to save the selected .c files in some string array say sourcefiles , .h files in string array say headerfiles and other files in some string array say resourcefiles. How do i do this? now i want to loop through all the sourcefiles, headerfiles and resourcefiles and then add these separately to VC++ solution using functions addsource,addheader and addresource. Then finally i need to copy these file to spme folder using relative path. How can i do all these things. My save in text file code is as given below.

    private void saveintextfile()
        {
          StreamWriter str = new StreamWriter("F:\\AFC\\Trace.txt");
          String inputText = "";
          foreach (TabPage item in this.tabcontrol1.TabPages)
          {
            inputText = "selected tabpage is " + item.Text + "\r\n";
            str.WriteLine(inputText);
            savechildintextfile(item, str, inputText);
          }
          //str.WriteLine(inputText);
          str.Flush();
          str.Close();
        }
    
    
        private void savechildintextfile(Control parent, StreamWriter str, String inputText)
        {
    
          //String inputText = "";
          foreach (Control item in parent.Controls)
          {
            if (item.Controls.Count > 0)
            {
              if (item.GetType() == typeof(GroupBox))
              {
                foreach (Control chk in item.Controls)
                {
                  if (chk.GetType() == typeof(FlowLayoutPanel))
                  {
                    foreach (Control finalchk in chk.Controls)
                    {
                      if (finalchk.GetType() == typeof(CheckBox))
                      {
                        CheckBox tempgrpcheckbox = (CheckBox)finalchk;
                        if (tempgrpcheckbox.Checked)
                        {
                          inputText = "selected subitem is " + tempgrpcheckbox.Text + "\r\n";
                          str.WriteLine(inputText);
                        }
                      }
                    }
    
                  }
                }
              }
              else
              {
                savechildintextfile(item, str, inputText);
              }
            }
            else
            {
              if (item.GetType() == typeof(CheckBox))
              {
                CheckBox tempcheckbox = (CheckBox)item;
                if (tempcheckbox.Checked)
                {
                  inputText = "selected item is " + tempcheckbox.Text + "\r\n";
                  str.WriteLine(inputText);
                }
              }
    
            }
          }
        }

    regards

    sahana

    Thursday, June 10, 2010 4:29 AM

Answers

  • you can use this function to add checked check boxes in string array

     

    just pass your parent control like tabcontrol or tabpage in this function

    private void getStringArray(Control parent)
            {
                String[] listOfCheckedChk = null;
                Int32 counter = 0;
                foreach (Control item in parent.Controls)
                {
                    if (item.Controls.Count > 0)
                    {
                        if (item.GetType() == typeof(GroupBox))
                        {
                            foreach (Control chk in item.Controls)
                            {
                                if (chk.GetType() == typeof(FlowLayoutPanel))
                                {
                                    foreach (Control finalchk in chk.Controls)
                                    {
                                        if (finalchk.GetType() == typeof(CheckBox))
                                        {
                                            CheckBox tempchk = (CheckBox)finalchk;
                                            {
                                                if (tempchk.Checked)
                                                {
                                                    listOfCheckedChk[counter] = tempchk.Text;
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                        else
                        {
                            this.getStringArray(item);
                        }
                    }
                }
            }

     

    regards

    jayant

    • Marked as answer by Harry Zhu Wednesday, June 16, 2010 3:06 AM
    Friday, June 11, 2010 8:22 AM