We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to perform the copy or paste in the foreign key reference column in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl
Tags: copypaste

Copy paste operation with foreign key

By default, the displayed cell value can be copied and pasted in any specified cell. In foreign key cell types, the copied values are the specific value members that have a foreign key reference of an object type. For example, while pasting the string type cell values to the foreign key cell and its foreign key is in the type of integer, the FormatException is thrown.

In order to copy-paste a cell value with a foreign key member field, a separate hash table instance can be used to store and retrieve the cell value from the foreign key cells and the corresponding display member values will be pasted in the required cell. This can be done through the PasteCellText event in the TableControl property.


// Declared globally
Hashtable hTable = new Hashtable();
// Form()
// Trigger the required event.
this.gridGroupingControl1.TableModel.PasteCellText += new GridPasteCellTextEventHandler(TableModel_PasteCellText);
// Form()
foreach (DataRow row in lookUpDataTable.Rows)
   if (!hTable.Contains(row["CustomerName"]))
       hTable.Add(row["CustomerName"], row["CustomerID"]);
void TableModel_PasteCellText(object sender, GridPasteCellTextEventArgs e)
   if (e.Style.CellType == "ForeignKeyCell")
      e.Cancel = true;
      GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(e.RowIndex, e.ColIndex);
      Record rec = style.TableCellIdentity.DisplayElement.GetRecord();
      rec.SetValue("Customer", hTable[e.Text].ToString());





' Declared globally
Dim hTable As New Hashtable()
' Form()
' Trigger the required event.
AddHandler gridGroupingControl1.TableModel.PasteCellText, AddressOf TableModel_PasteCellText
' Form()
For Each row As DataRow In lookUpDataTable.Rows
   If Not hTable.Contains(row("CustomerName")) Then
    hTable.Add(row("CustomerName"), row("CustomerID"))
   End If
Next row
void TableModel_PasteCellText(Object sender, GridPasteCellTextEventArgs e)
   If e.Style.CellType Is "ForeignKeyCell" Then
   e.Cancel = True
   Dim style As GridTableCellStyleInfo = Me.gridGroupingControl1.TableControl.GetTableViewStyleInfo(e.RowIndex, e.ColIndex)
   Dim rec As Record = style.TableCellIdentity.DisplayElement.GetRecord()
   rec.SetValue("Customer", hTable(e.Text).ToString())
   End If



Sort operation based on the member

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile