Satyapriya Nayak
posted
2264 posts
since
Mar 24, 2010
from
|
|
Re: How can I copy the listBox1???
|
|
|
|
|
|
|
|
|
|
|
Hi Ninja,
Try this...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO;
namespace listbox_copy { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { listBox1.Items.Add("a"); listBox1.Items.Add("b"); listBox1.Items.Add("c"); }
private void button1_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
foreach (object item in listBox1.Items)
sw.WriteLine(item.ToString());
sw.Close(); MessageBox.Show("Listbox items copied"); } } } }
Thanks
|
|
|
|
|
|
Csharp Ninja
posted
56 posts
since
Jan 16, 2012
from
|
|
Re: How can I copy the listBox1???
|
|
|
|
|
|
|
|
|
|
|
thank you very much bro. But I don't want to save as.. I want to copy listBox to clipboard.. how can I do that
|
|
|
|
|
|
Vulpes
posted
5419 posts
since
Feb 28, 2011
from
|
|
Re: How can I copy the listBox1???
|
|
|
|
|
|
|
|
|
|
Try this:
string temp = ""; foreach (object item in listBox1.Items) temp += item.ToString() + "\r\n"; Clipboard.SetText(temp);
|
|
|
|
|
|
Csharp Ninja
posted
56 posts
since
Jan 16, 2012
from
|
|
Re: How can I copy the listBox1???
|
|
|
|
|
|
|
|
|
|
|
Thank you very much Vulpes......... You are the best
Cheers
|
|
|
|
|
|
Sam Hobbs
posted
6490 posts
since
Sep 07, 2009
from
Los Angeles, California, USA
|
|
Re: How can I copy the listBox1???
|
|
|
|
|
|
|
|
|
|
|
Note that you would have gotten an answer sooner if you had said in your original question that you need to copy .... to the clipboard!
|
|
|
|
|
Thinking is a feeling; pleasant for some and unpleasant for others.
|
|
|
|
|
|