Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to copy a cell's value to other cells by dragging its right bottom edge

$
0
0

This example demonstrates how to provide the capability to copy cell values like this is done in MS Excel. In this example, when a cell is selected, you can see a small black rectangle at the bottom. If you drag this rectangle and extend GridView's selection, all selected cells will have the same value as that of a source cell.

Question Comments

Added By: Alex Vignola at: 4/19/2016 7:25:12 AM    Hi, first i'd like to report an error in one of the version of your code, and also a little addition.

In the v2010 vol1.4 - v2011 vol1.4 sample... In the SelectedCellsBorderHelper class, in the GetCellRect function, GetGridCellInfo should receive column.AbsoluteIndex and not column.VisibleIndex

Also if you want to handle non editable columns, one would need to modify two things
[VB.NET]
PrivateSub CopyCellsValues()Dim value AsObject = View.GetRowCellValue(SourceGridCell.RowHandle, SourceGridCell.Column)Dim selectedCells() As GridCell = View.GetSelectedCells()ForEach cell As GridCell In selectedCellsIf cell.Column.OptionsColumn.AllowEdit AndAlsoNot cell.Column.OptionsColumn.ReadOnlyThen View.SetRowCellValue(cell.RowHandle, cell.Column, value)EndIfNext cellEndSub

[VB.NET]
PrivateFunction GetSelectionBounds() As RectangleDim width AsInteger = 0Dim height AsInteger = 0Dim rTop As Rectangle = Rectangle.EmptyDim shouldReturn AsBoolean = FalseDim view As GridView = TryCast(GridControl.FocusedView, GridView)Dim info As GridViewInfo = TryCast(view.GetViewInfo(), GridViewInfo)Dim gridCells() As GridCell = view.GetSelectedCells()If gridCells.Length = 0 Then shouldReturn = TrueReturn Rectangle.EmptyEndIfDim hb As Brush = Brushes.BlackDim visibleColl AsNew List(Of GridCellInfo)()ForEach row As GridRowInfo In info.RowsInfoDim coll As GridCellInfoCollection = (TryCast(row, GridDataRowInfo)).CellsForEach cell As GridCellInfo In coll visibleColl.Add(cell)Next cellNext rowDim collection AsNew List(Of GridCellInfo)()ForEach cell As GridCell In gridCellsForEach cellInfo As GridCellInfo In visibleCollIf cellInfo.RowInfo IsNot NothingAndAlso cellInfo.ColumnInfo IsNot NothingThenIf cell.RowHandle = cellInfo.RowHandle AndAlso cell.Column.Equals(cellInfo.Column) AndAlsoNot cell.Column.OptionsColumn.ReadOnlyAndAlso cell.Column.OptionsColumn.AllowEdit Then collection.Add(cellInfo)EndIfEndIfNext cellInfoNext cellIf collection.Count = 0 Then shouldReturn = TrueReturn Rectangle.EmptyEndIf rTop = GetCellRect(view, collection(0).RowHandle, collection(0).Column)Dim rBottom As Rectangle = GetCellRect(view, collection(collection.Count - 1).RowHandle, collection(collection.Count - 1).Column)If rTop.Y > rBottom.Y Then height = rTop.Y - rBottom.BottomElse height = rBottom.Bottom - rTop.YEndIfIf rTop.X <= rBottom.X Then width = rBottom.Right - rTop.XElse width = rTop.X - rBottom.RightEndIfReturnNew Rectangle(rTop.X, rTop.Y, width, height)EndFunction


Added By: Stas (DevExpress Support) at: 4/20/2016 4:30:31 AM    Hello,
To address your question, I've created a separate Update the E2621 example ticket. Please refer to it for further discussion.

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>