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 copy the visible columns alone to clipboard in GridDataBound?

Platform: WinForms |
Control: GridDataBoundGrid(Classic)


By default, while copying cells with hidden rows and columns in GridDataBound control, the values of the hidden rows and columns will be pasted to the clipboard. To avoid this, we need to trace the hidden rows and columns and eliminate it using ClipboardCopy event of the GridDataBound control.


void Model_ClipboardCopy(object sender, Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs e)


GridRangeInfo range = e.RangeList.ActiveRange;

if (!range.IsEmpty)


range = range.ExpandRange(1, 1, this.gridDataBoundGrid1.Model.RowCount, this.gridDataBoundGrid1.Model.ColCount);

string s = "";

GridData data = this.gridDataBoundGrid1.Model.Data;

for (int row = range.Top; row <= range.Bottom; ++row)


if (!this.gridDataBoundGrid1.Model.Rows.Hidden[row])


bool firstCol = true;

for (int col = range.Left; col <= range.Right; ++col)


if (!this.gridDataBoundGrid1.Model.Cols.Hidden[col])


if (!firstCol) s += "\t";


firstCol = false;

s+= this.gridDataBoundGrid1.Model[row, col].CellValue;



s += Environment.NewLine;




e.Handled = true;





Private Sub Model_ClipboardCopy(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs)

Dim range As GridRangeInfo = e.RangeList.ActiveRange

If (Not range.IsEmpty) Then

range = range.ExpandRange(1, 1, Me.gridDataBoundGrid1.Model.RowCount,


Dim s As String = ""

Dim data As GridData = Me.gridDataBoundGrid1.Model.Data

Dim row As Integer = range.Top

Do While row <= range.Bottom

If (Not Me.gridDataBoundGrid1.Model.Rows.Hidden(row)) Then

Dim firstCol As Boolean = True

Dim col As Integer = range.Left

Do While col <= range.Right

If (Not Me.gridDataBoundGrid1.Model.Cols.Hidden(col)) Then

If (Not firstCol) Then

s &= Constants.vbTab


firstCol = False

End If

s &= Me.gridDataBoundGrid1.Model(row, col).CellValue.ToString()

End If

col += 1


s &= Environment.NewLine

End If

row += 1



e.Handled = True


End If

End Sub



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