473,383 Members | 1,984 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,383 software developers and data experts.

How to set rootpath of application which is the path of a selected item in listbox?

I want to set the rootpath of an executable application. This rootpath should be the same as the path of an item that I select from a ListBox. The code for selecting the item is as follows.
Expand|Select|Wrap|Line Numbers
  1. namespace Menu
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.  
  6.         private Button button;
  7.         private ListBox listBox1;
  8.         private string selecteditem;
  9.  
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void Form1_Load(object sender, EventArgs e)
  16.         {
  17.  
  18.             button = new Button();
  19.             button.Text = "Create ListBox";
  20.             button.AutoSize = true;
  21.             button.Location = new Point(100, 150);
  22.             button.Click += button1_Click;
  23.             this.Controls.Add(button);
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             listBox1 = new ListBox();
  29.             listBox1.AutoSize = true;
  30.             listBox1.Location = new Point(75, 100);
  31.  
  32.             listBox1.MultiColumn = true;
  33.             listBox1.BeginUpdate();
  34.             listBox1.DoubleClick += listBox1_DoubleClick;
  35.             this.Controls.Add(listBox1);
  36.  
  37.  
  38.             listBox1.Items.Add("N-TYPE1");
  39.             listBox1.Items.Add("N-TYPE2");
  40.             listBox1.Items.Add("N-TYPE3");
  41.             listBox1.Items.Add("N-TYPE4");
  42.             listBox1.Items.Add("N-TYPE5");
  43.  
  44.         }
  45.  
  46.         private void listBox1_DoubleClick(object sender, EventArgs e)
  47.         {
  48.             selecteditem = String.Empty;
  49.  
  50.             string path = "E:\\New Files\\";
  51.             string subPath = "\\D1\\";
  52.             string subPath2 = "\\S1";
  53.  
  54.             if (listBox1.SelectedItems.Count > 0)
  55.             {
  56.                 selecteditem = listBox1.SelectedItem.ToString();
  57.                 if (!Directory.Exists(path + "\\" + selecteditem))
  58.                 {
  59.                     Directory.CreateDirectory(path + "\\" + selecteditem);
  60.                 }
  61.                 if (!Directory.Exists(path + "\\" + selecteditem + subPath))
  62.                 {
  63.                     Directory.CreateDirectory(path + "\\" + selecteditem + subPath);
  64.                 }
  65.                 if (!Directory.Exists(path + "\\" + selecteditem + subPath2))
  66.                 {
  67.                     Directory.CreateDirectory(path + "\\" + selecteditem + subPath2);
  68.                 }
  69.  
  70.                 else
  71.                 {
  72.                     //Do nothing
  73.                 }
  74.                 Console.WriteLine(path + selecteditem);
  75.  
  76.  
  77.                 listBox1.ClearSelected();
  78.             }
  79.  
  80.         }
  81.     }
  82. }
Now what I want is: Whatever I get the output as in the
Console.Writeline(path + selecteditem), I would want to set this as a rootpath for an application so as to do rest of the measurements or steps only in tht path/folder.
Is it possible to do something like this?
Thank you in advance for your help.
Apr 4 '13 #1
8 1676
vijay6
158 100+
Hey user033088, After creating the directory copy and paste your application (with all the supporting files) which you want to start from directory. For this operation you can use 'File.Copy()' method. And to run that application you can use 'Process.Start()' method.

Expand|Select|Wrap|Line Numbers
  1. System.IO.File.Copy("Source filename with path", "Destination filename with path");
  2.  
  3. System.Diagnostics.Process.Start("Filename with path");
Apr 5 '13 #2
I am sorry but could you please clear this for me. When you say "After creating the directory copy and paste your application (with all the supporting files) which you want to start from directory."
Does this mean after I create the E:\\New Files\\ directory I should paste the application .exe file here? Because what I am looking for is basically changing the user control and am not sure how that is possible. Once the application starts the user basically has to browse through in order to set a path. I want to set this path as same as the selected item in listBox.
Does this make sense? Many thanks is advance..!!
Apr 8 '13 #3
vijay6
158 100+
Hey user033088, i think i misunderstood your requirement. Can you explain your requirement briefly? What you want to save on that location?
Apr 9 '13 #4
So with the code that I wrote till now, I get output as a path of whatever item is selected. For example if I Double click on N-TYPE4, firstly E:\New Files will be created and then E:\New Files\N-TYPE4. And, then the sub directories. What I am mainly interested is in the selected item path which is E:\New Files\N-TYPE4. Now, I have an application which basically is used for measurements of electrical components. This application once started has a option of selecting a rootpath on its menu/toolStrip (this is once the application is started or after you run it) I want this rootpath to be set as the one which we selected in the listBox which is E:\New Files\N-TYPE4.
For now, in my application I am setting this path in my code as follows:
Expand|Select|Wrap|Line Numbers
  1.  public VensTs()
  2.         {
  3.             Settings.Default.RootPath = "E:\\New Files";
  4.             Settings.Default.RootPathDatabase =
  5. "C:\\Users\\Public\\Documents\\Vens.Ts\\Database";
  6.             this.resetOnRootPathChange = true;
  7.             this.rootPath = Settings.Default.RootPath;
  8.             this.InitializeComponent();
  9.             this.Init();
  10.         }
But I am looking for an easier way, if I select a Directory in the listBox, it should change this path as same as the listBox selected item. Does this make any sense? Thank You for replying.
Apr 9 '13 #5
vijay6
158 100+
Hey user033088, so you've two applications? One is for "measurements of electrical components" and another one is to create directory?
Apr 10 '13 #6
Yes both are different applications (Forms) I have another question posted asking for the same thing and you replied to that too. It is basically continuity of this part only. They are 2 different applications but I want the output (i.e the selected item path) to be used in form2.
Apr 10 '13 #7
The first code here is used to create the directories. So basically it creates E:\New Files\N-TYPE4 and its sub directories after I double click on N-TYPE4. Now the second code is a part of code for the main application which is used for measurements of electrical components. Its a huge code so cannot post here but the main part where is I make change in the part where it is
Expand|Select|Wrap|Line Numbers
  1. Settings.Default.RootPath = "E:\\New Files";
if I change here E:\\New Files\\N-TYPE4 then it is set but I want this to be done automatically. Like I do not want to make the change in the code every time. I want that whatever item is selected the application (measurement for electrical components) should know about it. Is it possible??
Thank You for replying back to me!!
Apr 10 '13 #8
vijay6
158 100+
Hey user033088, 'm again confused. In your another question you said "Passing the listBox1.SelectedItem value from one form to another?" But here you said "Yes both are different applications".

Two different applications or one application with multiple forms?

If your requirement/question is 'one application with multiple forms' means try like this,

In 'Form1' while calling 'Form2' pass an argument as listbox1's selectedItem value. Like as follows,


Expand|Select|Wrap|Line Numbers
  1. Form2 form2 = new Form2(listbox1.SelectedItem.ToString());
  2. form2.Show();


And in 'Form2' create a new constructor with one string argument. Like as follows,


Expand|Select|Wrap|Line Numbers
  1. public Form2(string value)
  2. {
  3.         //MessageBox.Show(value);
  4.         //Settings.Default.RootPath = "E:\\New Files";
  5.         Settings.Default.RootPath = "E:\\New Files\\" + value;
  6. }
Apr 11 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
4
by: Filips Benoit | last post by:
Dear All, I have code that selects - find and select - 1 item in a large listbox. This works Ok but most of the time the selected item isn't visible without scrolling down manualy. Is this...
1
by: | last post by:
Hello everybody... How can i unplug selected item in Listbox. Thanks in advance. Paulo
2
by: Alpha | last post by:
How do I change the selected item in a listbox according to a Combox's selected item on the same form? The Combox is from a different table in the same dataset as the Listbox uses. Combox's...
6
by: David De Cotis | last post by:
Hello all, I am trying to go through a ListBox and verify if am item was selected. If an item was selected, I would like to get a handle of the item and simply do a response.write on the selected...
1
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
0
by: scartin | last post by:
Hi, I have a multi-select ListBox that shows 5 rows at a time, but contains possibly a hundred or more items. As I retrieve relevant data from the database, I set the SelectedIndex of the rows...
3
by: peter.mosley | last post by:
I've tried googling for the answer to this problem, without any luck. I'm sure the truth must be out there somewhere! I have a multiselect listbox populated with many items (set by the RowSource...
1
by: Gerardo ARnaez | last post by:
Hi. I am writing a program to help determine coumadin regimens to look at the code: http://sourceforge.net/projects/coumadinregimen/ The issue is that I have a variable that I want the use to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.