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
close icon

During column cut

Hi, I have header column row and i have one more header row where i have set units for the columns.This i did by setting the header row = 1 When i m cutting the column from one position and pasting to some location this header row is getting deleteing.Content of the rest of the rows are proper. why is this happening?

5 Replies

AD Administrator Syncfusion Team December 15, 2004 08:17 AM UTC

If this is a GridDataBoundGrid (as opposed to a GridControl), the default paste only paste text information. It does not paste style information. So, is the inforamtion you are putting in your extra header held in the style.Text property for the cell? If not, the default paste will not work for you. You can handle the grid.Model.ClipboardPaste event and do what you want with teh data that is on the clipboard. You can also handle the ClipboardCopy event and put extra data into the clipboard as well.


AD Administrator Syncfusion Team December 16, 2004 01:56 AM UTC

I am not cutting and pasting the contents. Everytime i m removing the column from the GridBoundColumnsCollection and inserting when required. But the content of the header row is deleted.I am not doing anything specific for other rows of the columns I have attached the function for cut and insert. Also is there any better way of doing this? /// /// Cuts the selected columns /// /// /// /// private void m_MenuItemCutCols_ClickEventHandler( object sender, EventArgs e ) { m_HasCutColCalled = true; GridBoundColumnsCollection col = (GridBoundColumnsCollection) this.m_PretestListingGrid.GridBoundColumns.Clone(); if (col.Count == 0) col = this.m_PretestListingGrid.Binder.InternalColumns; this.m_PretestListingGrid.GridBoundColumns.Clear(); //Contains the list of the cut columns m_CutCols.Clear(); //Get the selected columns range GridRangeInfoList ranges = null; this.m_PretestListingGrid.Selections.GetSelectedRanges( out ranges, false); ArrayList colsHeadersToRm = new ArrayList(); foreach (GridRangeInfo range in ranges) { switch (range.RangeType) { case GridRangeInfoType.Cells: if (!colsHeadersToRm.Contains(range.Left - 1)) { colsHeadersToRm.Add(range.Left - 1); } break; case GridRangeInfoType.Cols: if (!colsHeadersToRm.Contains(range.Right - 1)) { colsHeadersToRm.Add(range.Right - 1); } if (!colsHeadersToRm.Contains(range.Left - 1 )) { colsHeadersToRm.Add(range.Left - 1); } break; } } if (!colsHeadersToRm.Contains(m_LastCol - 1)) { colsHeadersToRm.Add(m_LastCol - 1); } colsHeadersToRm.Sort(); for (int i = 0; i < col.Count; i++) { bool bCutCell = false; GridBoundColumn column = col[i]; for (int j = 0;j < colsHeadersToRm.Count; j++) { if ((int)colsHeadersToRm[j] == i) { //Add the cut columns m_CutCols.Add(column); bCutCell = true; } } if ( bCutCell == false) { this.m_PretestListingGrid.GridBoundColumns.Add(column); } } if (m_HasCutColCalled == true) { this.m_MenuItemInsertCutCol.Enabled = true; } m_PretestListingGrid.Binder.InitializeColumns(); for (int m = 0; m < m_HiddenCols.Count; m++) { GridBoundColumn column =(GridBoundColumn)m_HiddenCols[m]; int colIndex = GetPosition(column.HeaderText); this.m_PretestListingGrid.Model.Cols.Hidden[colIndex] = true; } m_PretestListingGrid.Refresh(); return; } /// /// Insert cut columns /// /// /// /// private void m_MenuItemInsertCutCol_ClickEventHandler( object sender, EventArgs e ) { GridBoundColumnsCollection col = (GridBoundColumnsCollection) this.m_PretestListingGrid.GridBoundColumns.Clone(); if (col.Count == 0) col = this.m_PretestListingGrid.Binder.InternalColumns; this.m_PretestListingGrid.GridBoundColumns.Clear(); GridBoundColumn column = null; this.m_PretestListingGrid.Model.Cols.Hidden.ResetRange(0,col.Count); //Form the grid bound columns again and //Add the cut column for (int i = 0; i < col.Count; i++) { if (i == m_LastCol - 1 ) { for (int j = 0;j < m_CutCols.Count; j++) { column = (Syncfusion.Windows.Forms.Grid.GridBoundColumn) m_CutCols[j]; this.m_PretestListingGrid.GridBoundColumns.Add(column); m_PretestListingGrid.Binder.InitializeColumns(); } } column = col[i]; this.m_PretestListingGrid.GridBoundColumns.Add(column); m_PretestListingGrid.Binder.InitializeColumns(); } //disable the insert cut column this.m_MenuItemInsertCutCol.Enabled = false; m_PretestListingGrid.Binder.InitializeColumns(); m_PretestListingGrid.Refresh(); for (int m = 0; m < m_HiddenCols.Count; m++) { GridBoundColumn gridCol =(GridBoundColumn)m_HiddenCols[m]; int colIndex = GetPosition(gridCol.HeaderText); this.m_PretestListingGrid.Model.Cols.Hidden[colIndex] = true; } this.m_PretestListingGrid.Model.ColWidths.ResizeToFit( GridRangeInfo.Row(0),GridResizeToFitOptions.IncludeHeaders); m_HasCutColCalled = false; return; } >If this is a GridDataBoundGrid (as opposed to a GridControl), the default paste only paste text information. It does not paste style information. So, is the inforamtion you are putting in your extra header held in the style.Text property for the cell? If not, the default paste will not work for you. > >You can handle the grid.Model.ClipboardPaste event and do what you want with teh data that is on the clipboard. You can also handle the ClipboardCopy event and put extra data into the clipboard as well.


AD Administrator Syncfusion Team December 16, 2004 09:34 AM UTC

I do not know of a better way to do this. Here is a working sample that does something similar to your posted code. It allows you to select coloumns and then right-click and cut them. Then right-click and paste them. http://64.78.18.34/Support/user/uploads/GDBG_CutPasteCols.zip


AD Administrator Syncfusion Team December 20, 2004 12:13 AM UTC

Yes. I have added one line to your code and simulated my behavior. Now when i cut column that header row goes off can you tell how this problem can be solved? I am not able to upload the zip files. can you just add one line gridDataBoundGrid1.Model.Rows.HeaderCount = 1; //Added to the form load method and run. >I do not know of a better way to do this. Here is a working sample that does something similar to your posted code. It allows you to select coloumns and then right-click and cut them. Then right-click and paste them. > >http://64.78.18.34/Support/user/uploads/GDBG_CutPasteCols.zip


AD Administrator Syncfusion Team December 20, 2004 06:43 AM UTC

There are two calls to this.gridDataBoundGrid1.Binder.InitializeColumns, one in cut and one in paste. It is these calls that are removing the extra headers. One way you can handle this is to add the extra headers back after the call. (You would need to do whatever you are doing now to provide the contents as well.) So, in the sample, after the calls to InitializeColumns, you can add gridDataBoundGrid1.Model.Rows.HeaderCount = 1; to avoid the problem. In your code, you would likely call a method that added the header row and initialized its contents somehow.

Loader.
Live Chat Icon For mobile
Up arrow icon