Getting data from listview
-
Hi i am having an issue about getting data from list view. I am wanting to get data from a listview and place it in 3 textboxes. Here is the code i have to place it from the 3 textboxes to the listview but i am wanting to reverse this.
string\[\] myItems = new string\[\] { textBox1.Text, textBox2.Text, textBox3.Text }; ListViewItem lvi = new ListViewItem(myItems); listView1.Items.Add(lvi);
thanks for you help in advance Don't be overcome by evil, but overcome evil with good
-
Hi i am having an issue about getting data from list view. I am wanting to get data from a listview and place it in 3 textboxes. Here is the code i have to place it from the 3 textboxes to the listview but i am wanting to reverse this.
string\[\] myItems = new string\[\] { textBox1.Text, textBox2.Text, textBox3.Text }; ListViewItem lvi = new ListViewItem(myItems); listView1.Items.Add(lvi);
thanks for you help in advance Don't be overcome by evil, but overcome evil with good
To get the data from a list view you use the Items property. For example if you wanted to get the data from the selected item in the list:
int selected = listView1.SelectedItems[0].Index; // get the first selected item's index textBox1.Text = listView1.Items[selected].Text // to get the data in the the first column. textBox2.Text = listView1.Items[selected].SubItems[1].Text; // to get the data in the second column
And so on... Hope that helps :laugh:
-
To get the data from a list view you use the Items property. For example if you wanted to get the data from the selected item in the list:
int selected = listView1.SelectedItems[0].Index; // get the first selected item's index textBox1.Text = listView1.Items[selected].Text // to get the data in the the first column. textBox2.Text = listView1.Items[selected].SubItems[1].Text; // to get the data in the second column
And so on... Hope that helps :laugh:
Thanks for your help sean. I tried that but i couldn't get it to work. Let me explain what i have going on in this program. First i have a button that opens an "openFileDialog". After i select the file it puts the fileName in textbox1.text, in textbox2.text it has the filetype, in textbox3.text it has "pending". Then after that i have it set up to move to the listview by the code i posted above. What i'm wanting to do is to be able to push a button and it will move the filename back from the listview to textbox1.text. Then from there i will be able to do File.Copy(path, path2) ((path would be textbox1.text)) I don't know if you even understand what i'm saying (i think i just confused myself as i'm posting this). As you can tell i am still learning :) Don't be overcome by evil, but overcome evil with good
-
Thanks for your help sean. I tried that but i couldn't get it to work. Let me explain what i have going on in this program. First i have a button that opens an "openFileDialog". After i select the file it puts the fileName in textbox1.text, in textbox2.text it has the filetype, in textbox3.text it has "pending". Then after that i have it set up to move to the listview by the code i posted above. What i'm wanting to do is to be able to push a button and it will move the filename back from the listview to textbox1.text. Then from there i will be able to do File.Copy(path, path2) ((path would be textbox1.text)) I don't know if you even understand what i'm saying (i think i just confused myself as i'm posting this). As you can tell i am still learning :) Don't be overcome by evil, but overcome evil with good
I understand what your trying to do ;) The only way I know how to get the data from the list view is by the way I posted earlier. Thats odd that this is not working for you though :confused: Could you post the code that you have written to get the data out of the list view?
-
I understand what your trying to do ;) The only way I know how to get the data from the list view is by the way I posted earlier. Thats odd that this is not working for you though :confused: Could you post the code that you have written to get the data out of the list view?
Alright here is what i got going on: This button does the openfile and puts it in the textboxes:
private void button1\_Click(object sender, EventArgs e) { OpenFileDialog music = new OpenFileDialog(); music.Title = "Add a music file"; music.InitialDirectory = "C:\\\\"; music.Filter = "Supported File Types|\*.mp3,\*.wma|All files (\*.\*)|\*.\*"; music.FilterIndex = 2; music.RestoreDirectory = false; if (music.ShowDialog() == DialogResult.OK) { music.Multiselect = true; foreach (string fileName in music.FileNames) { textBox1.Text = fileName; textBox2.Text = "Audio"; textBox3.Text = "Pending"; } string\[\] myItems = new string\[\] { textBox1.Text, textBox2.Text, textBox3.Text }; ListViewItem lvi = new ListViewItem(myItems); listView1.Items.Add(lvi); } }
what i'm wanting to do before i do file.copy is move the filename in the listview back to textbox1.text (textbox2 and 3 also but it doesn't really matter as of right now)
private void button6\_Click(object sender, EventArgs e) { string path = textBox1.Text; string path2 = textBox4.Text; try { // Copy the file. File.Copy(path, path2); this.syncstat.Text = "Status: Files Copied"; } catch { this.syncstat.Text = "Status: Cannot copy into the same folder"; }
Don't be overcome by evil, but overcome evil with good
-
I understand what your trying to do ;) The only way I know how to get the data from the list view is by the way I posted earlier. Thats odd that this is not working for you though :confused: Could you post the code that you have written to get the data out of the list view?
I'm sorry sean i shoulda read more clearly. this is how i tested it
private void button6\_Click(object sender, EventArgs e) { int selected = listView1.SelectedItems\[0\].Index; // get the first selected item's index textBox1.Text = listView1.Items\[selected\].Text; // to get the data in the the first column. textBox2.Text = listView1.Items\[selected\].SubItems\[1\].Text; // to get the data in the second column textBox3.Text = listView1.Items\[selected\].SubItems\[2\].Text; }
but i couldn't get it to show in the 3 boxes Don't be overcome by evil, but overcome evil with good
-
Hi i am having an issue about getting data from list view. I am wanting to get data from a listview and place it in 3 textboxes. Here is the code i have to place it from the 3 textboxes to the listview but i am wanting to reverse this.
string\[\] myItems = new string\[\] { textBox1.Text, textBox2.Text, textBox3.Text }; ListViewItem lvi = new ListViewItem(myItems); listView1.Items.Add(lvi);
thanks for you help in advance Don't be overcome by evil, but overcome evil with good
I dont know if this works but I doubt it cause its wierd the way your putting it to a question: ListViewItem myItems = (ListViewItem) listView1.SelectedItems[0]; textBox1.Text = myItems.Text; textBox2.Text = myItems.SubItems[0].Text; textBox3.Text = myItems.SubItems[1].Text; But thats just my guess :shrug:
-
I'm sorry sean i shoulda read more clearly. this is how i tested it
private void button6\_Click(object sender, EventArgs e) { int selected = listView1.SelectedItems\[0\].Index; // get the first selected item's index textBox1.Text = listView1.Items\[selected\].Text; // to get the data in the the first column. textBox2.Text = listView1.Items\[selected\].SubItems\[1\].Text; // to get the data in the second column textBox3.Text = listView1.Items\[selected\].SubItems\[2\].Text; }
but i couldn't get it to show in the 3 boxes Don't be overcome by evil, but overcome evil with good