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

Set Currentcell!

want to set the currentcell! at the moment the grid.currentcell.rowindex or colindex are -1 now i want to set rowindex = 2 and colindex =5 any idea?

5 Replies

Administrator January 22, 2004 12:50 PM UTC

this.grid.CurrentCell.MoveTo(5,2); If you are trying the in formload, you also may have to set this.grid.ForceCurrentCellMoveTo = true;

PB Philip Bishop April 6, 2004 10:03 AM UTC

I have a question similar to this. I have attached a sample where the user clicks a button where it ends the edit of the cell. Then if the user clicks another cell, the first cell they selected stays highlighted. It has to do with the celldrawn even that u had us add to let the cell stay selected when a user clicks a button and thats fine. I want to know how to make it so when the user clicks another cell that the first cell becomes unselected. SelectText_8867.zip

Administrator April 6, 2004 11:13 AM UTC

One way you can do it is to refresh the old cell after drawing the rectangle over the new cell.
Private oldRow As Integer = -1
Private oldCol As Integer = -1

Private Sub Grid1_CellDrawn(ByVal sender As Object, ByVal e As GridDrawCellEventArgs) Handles Grid1.CellDrawn
Dim cc As GridCurrentCell = Me.Grid1.CurrentCell
If e.ColIndex = cc.ColIndex AndAlso e.RowIndex = cc.RowIndex AndAlso Not Me.Grid1.PrintingMode Then
       Dim brush As New SolidBrush(Me.Grid1.AlphaBlendSelectionColor)
        Try
                e.Graphics.FillRectangle(brush, e.Bounds)
            Finally
                brush.Dispose()
            End Try
            If oldRow > -1 And oldCol > -1 And (oldRow <> e.RowIndex Or oldCol <> e.ColIndex) Then
                Grid1.RefreshRange(GridRangeInfo.Cell(oldRow, oldCol))
            End If
            oldRow = e.RowIndex
            oldCol = e.ColIndex
        End If
  End Sub

PB Philip Bishop April 6, 2004 11:36 AM UTC

Clay, Once again thanx for the prompt response but arent you suppose to be on vacation?? Anyway that works but what does the -1 do on those 2 variables you set up?? Phil

PB Philip Bishop April 6, 2004 11:40 AM UTC

Hey i figured that out. Thanks
Loader.
Live Chat Icon For mobile
Up arrow icon