Reputation: 221
Example scenario: When copying a line from Microsoft Word, it gets copied to clipboard and the text can be pasted to notepad and to others as well.
My problem: I want to develop an application that can copy a tuple from MySQL database. From the copied tuple, each column's data shall be stored in an array and while pasting to another application's textboxes, the data must be pasted one data per textbox till the end of tuple.
i.e. an application has a form with 5 textboxes: textbox1, textbox2, textbox3, textbox4, textbox5 and database table has 5 columns with data stored.
The designed application will show the data from database, and while copying the tuple, it must be stored in array as a[0], a[1], a[2], a[3], a[4] . Then while pasting it to another application with those 5 textboxes, only a[0] 's data must be stored to textbox1, only a[1] 's data must be stored to textbox2, and so forth.
Can this be achieved? If it can be, how could this problem be resolved. Forgive me if I asked too much.
Regards, Nipun Shakya
Upvotes: 0
Views: 525
Reputation: 54433
Well you obviously can't have your users interact with mySql directly, but I guess that's not what you mean?
You can control both ends, the source and the target? If that is so, all you need to do is decide on a format you can put into the clipboard and retrieve again
Here is a simple sample to get you started.
For demonstartion only it uses a ListView
and upon Ctl-C
copies each Item's Text to the Clipboard
, spearating them by a vertical tab.
Upon a Ctl-V
in the TextBox all those string are split again and each inserted on a separate line.
private void lv_files_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control)
{
string data = "";
foreach (ListViewItem lvi in lv_files.Items) data += lvi.Text + "\v";
Clipboard.SetData(DataFormats.Text, data); ;
e.Handled = true;
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control)
{
string data = Clipboard.GetData(DataFormats.Text).ToString();
var parts = data.Split('\v');
foreach (string p in parts) textBox1.Text += p + "\r\n";
Clipboard.Clear();
e.Handled = true;
}
}
This should be expanded with these features:
Shift-Insert
and Ctrl-Insert
ListView
use your source; you can't have a user interaction with a DataTable
, so you need some stand-in Control. Of course a DataGridView
comes to mind, but it really could be anthing that can get focus and listen to KeyDown.TextBox
you should put the data to the target TextBoxes
; maybe you can put them in List<TextBox>
to make accessing them simple..Upvotes: 0