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 do I paste clipboard contents bigger than GridDataBoundGrid row and column count?

Platform: WinForms |
Control: GridDataBoundGrid(Classic)


The GridDataBoundGrid does not increment the row and column count as in the GridControl. The reason is that the GridDataBoundGrid does not have its own datastore, it has to store these in the relevant datatable. To add rows and columns in the datatable, the Model.ClipboardPaste handler must be used.

In this handler, the clipboard contents that are stored in text format of DataObject will be a single string. This has to be split with '\n' and '\t' to refer the rows and columns fashion and this count is compared with the existing row and column count. The necessary extra rows are added then and makes pasting possible.


this.gridDataBoundGrid1.UseListChangedEvent = false;

DataObject data = (DataObject) Clipboard.GetDataObject();

//gets the size of the data object in rows

string s = (string)data.GetData(DataFormats.Text);

string[] rows = s.Split(new char[]{'\n'});

int numRows = rows.GetLength(0);

if(numRows > 0 && rows[numRows - 1].Length == 0)

numRows--; //removes extra empty row if present

//gets the size of the data object in Columns

string[] cols = rows[0].Split(new char[]{'\t'});

int numCols = cols.GetLength(0);

if(numCols > 0 && cols[numCols - 1].Length == 0)

numCols--; //removes extra empty column if present

int extraRowIfStartAtAddNewRow = this.gridDataBoundGrid1.Binder.IsAddNew ? 1 : 0;

while(currentCell.RowIndex + numRows + extraRowIfStartAtAddNewRow > grid.Model.RowCount)


DataRow dr = dt.NewRow();




while(currentCell.COlIndex + numCols > grid.Model.ColCount+1)








Me.gridDataBoundGrid1.UseListChangedEvent = False

data As DataObject = CType(Clipboard.GetDataObject(), DataObject)

'gets the size of the data object in rows

s As String = CStr(data.GetData(DataFormats.Text))

rows As String() = s.Split(New Char(){ControlChars.Lf})

numRows As Integer = rows.GetLength(0)

If numRows > 0 AndAlso rows(numRows - 1).Length = 0 Then

numRows -= 1 'removes extra empty row if present

End If

'gets the size of the data object in Columns

Dim cols As String() = rows(0).Split(New Char(){ControlChars.Tab})

Dim numCols As Integer = cols.GetLength(0)

If numCols > 0 AndAlso cols(numCols - 1).Length = 0 Then

numCols -= 1 'removes extra empty column if present

End If

Dim extraRowIfStartAtAddNewRow As Integer = IIf(Me.gridDataBoundGrid1.Binder.IsAddNew, 1, 0)

Do While currentCell.RowIndex + numRows + extraRowIfStartAtAddNewRow > grid.Model.RowCount

Dim dr As DataRow = dt.NewRow()


row -= 1


Do While currentCell.COlIndex + numCols> grid.Model.ColCount+1


col -= 1




Here is a sample that illustrates this:


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