The above code looks like it will handle TextBoxes and ComboBoxes, which is great, but anyone got any code to handle columns within a DataGridView
The above code looks like it will handle TextBoxes and ComboBoxes, which is great, but anyone got any code to handle columns within a DataGridView
HiŁ¬Chris Gin
What kind of work do you want to do whiling handling columns within a DGV
And, I recommend you to start a new thread to ask your question.
Best Regards.
Ye
Hi,Chris Gin
In fact, when datagridview is in edit mode,for example,a certain cell is being edited,form.ActiveControl will return a textbox type control which represents this current editing cell(in fact,once a cell change into edit mode,the editingControlShowing event fires,making a datagridviewTextBoxEditingControl hosted in this cell),thus the copy/cut/paste/undo operation in my previous code works as well in this scenario.While in unedit mode,i.e. you select some of the cells,click the Copy menuItem,the text in these cells will be copied to the Clipboard,later when you click the Paste menuItem,these text will be pasted in somewhere you focus,to achieve this,I think up a way as following:
private void copyToolStripMenuItem_Click(object sender, EventArgs e)< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
{
Control ctrl = this.ActiveControl;
if (ctrl != null)
{
if (ctrl is TextBox)
{
TextBox tx = (TextBox)ctrl;
tx.Copy();
}
if (ctrl is myComboBox)
{
myComboBox cb = (myComboBox)ctrl;
cb.Copy();
}
if (ctrl is DataGridView)
{
DataGridView dgv = (DataGridView)ctrl;
string content = "";
foreach (DataGridViewCell cell in dgv.SelectedCells)
{
content += cell.Value.ToString() + "\t";
}
}
}
}
but, to cut in unedit mode is not recommended,because it may result in some exceptions,you may have seen that the ctrl+x(cut) hotkey is not work in unedit mode.Neither does the paste operation.
Hope it helps.
Best Regards.
Ye