Click to See Complete Forum and Search --> : Clipboard problem


Galen
January 10th, 2006, 02:58 PM
For the datagrid I'm trying to append the column headers to the clipboard whenever the user copys rows. I capture ctrl+c by overriding the ProcessCmdKey function of DataGrid. My solution works the first time, but anytime after that the clipboard isn't updated and the column headers are appended to the old clipboard contents again. I don't understand why the clipboard isn't being updated. I call ProcessCmdKey from the base class, so I thought it would be handled. Any help would be appreciated.


bool ProcessCmdKey(Message* msg, Keys keyData)
{
bool b = System::Windows::Forms::Control::ProcessCmdKey (msg, keyData);

if (keyData == (Keys::Control | Keys::C))
{
IDataObject* iData = Clipboard::GetDataObject();
if(iData->GetDataPresent(DataFormats::Text))
{
Object *obj = iData->GetData(DataFormats::Text);
String *s = Convert::ToString(obj);

DataTable* dt = dynamic_cast<DataSet*>(this->DataSource)->Tables->Item[CurrentTable];
if(dt != NULL)
{
String* s1 = "";
for(int col = 0; col < dt->Columns->Count; col++)
{
if(col > 0) s1 = String::Concat(s1, S"\t");
s1 = String::Concat(s1,dt->Columns->Item[col]->ColumnName);
}
s = String::Concat(s1,S"\r\n",s);
Clipboard::SetDataObject(s, true);
return true;
}
}
}
return b;
}