Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13880 |

    hello

    i would like to know if it s possible to select more than 1 cell in the same row ?

    i would like to do like excel selection: i want to select 3 or 4 cells and apply some actions, like change color

    thx

    Imported from legacy forums. Posted by hebeldark (had 6588 views)

    User (Old forums)
    Member
    Post count: 23064

    I too am in need of such functionality. Please send help!

    Imported from legacy forums. Posted by DrWurm (had 317 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m sorry, but I don’t think the GridControl was designed for this. That doesn’t mean you can’t have such functionality, it just means you’ll have to build that functionality yourself. You can turn off row-selecting by setting the <b>SelectionMode</b> property of the GridControl to <b>SelectionMode.None</b> and then handle all the selecting yourself. Maybe you could create custom Row- and Cell-classes for this.

    Imported from legacy forums. Posted by Tommy (had 227 views)

    User (Old forums)
    Member
    Post count: 23064

    Boo… haha… I’ll let you know if I come up with a decent method for this sometime.

    Imported from legacy forums. Posted by DrWurm (had 508 views)

    User (Old forums)
    Member
    Post count: 23064

    I am playing with this a bit and I am running into a few complications.

    I’m just wondering if anyone has had any luck getting the visibleindex of a row. I noticed that Tommy had posted on this topic before and in order to implement such a feature, I believe I will need a quick way to grab the visible index of a row.

    Imported from legacy forums. Posted by DrWurm (had 375 views)

    User (Old forums)
    Member
    Post count: 23064

    To get the visible index of a DataRow: myGrid.GetSortedDataRows(true).IndexOf(myDataRow);

    Imported from legacy forums. Posted by Tommy (had 354 views)

    User (Old forums)
    Member
    Post count: 23064

    Yeah, thanks Tommy. That is exactly what i needed.

    Imported from legacy forums. Posted by DrWurm (had 290 views)

    User (Old forums)
    Member
    Post count: 23064

    Here is what I have done so far. I hope it is OK that I’m posting so much code in the forum rather than providing a link to the file.

    This should be a good start. It is not designed to work with most of the features that the xceed grid can do, so for learning / testing purposes I would stick to a non master/detail grid.

    I am very new to the xceed grid so please let me know if you see anything that can be done in a much better way!

    <pre>
    ‘=============================================================

    ‘ CellSelect Class

    ‘ NOTE: This is not intended to be anything miraculous at all
    ‘ it merely shows that this sort of thing can be done


    ‘ USE: Create a new instance of the CellSelect object passing
    ‘ in the instance of the grid you wish to use this on

    ‘ After data has filled the grid, call the initialization
    ‘ function

    ‘ Again, this is probably not anything you can use in
    ‘ its exact form, but it should be a good start to help
    ‘ you achieve what you are looking for. I hope someone
    ‘ finds this moderately useful

    ‘=============================================================

    Public Class CellSelect
    Dim grdGRID As Xceed.Grid.GridControl
    Dim SELECTEDCELLS As New ArrayList ‘ An arraylist containing all of the currently selected cells
    Dim startX As Integer
    Dim starty As Integer
    Dim MOUSEDOWN As Boolean = False
    Dim BGColor As Color = Color.Fuchsia ‘just to remind me that I need to set a decent color

    Sub New(ByVal ingrid As Xceed.Grid.GridControl, ByVal newcolor As Color)
    grdGRID = ingrid
    BGColor = newcolor
    ingrid.SelectionMode = SelectionMode.None
    End Sub

    Public Function initialize()
    Dim CurrCell As Xceed.Grid.Cell
    Dim row As Xceed.Grid.DataRow

    ‘======


    ‘ Add mouse events to each cell


    ‘======
    For Each row In grdGRID.DataRows
    For Each CurrCell In row.Cells
    AddHandler CurrCell.MouseDown, AddressOf CellMouseDown
    AddHandler CurrCell.MouseUp, AddressOf CellMouseUp
    AddHandler CurrCell.MouseMove, AddressOf CellMouseMove
    AddHandler CurrCell.CellViewerChanged, AddressOf CellEdit
    Next
    Next
    ‘—======

    End Function

    Private Sub CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Dim inCell As Xceed.Grid.Cell
    Dim x As Integer

    MOUSEDOWN = True
    For x = 0 To SELECTEDCELLS.Count – 1
    CType(SELECTEDCELLS(x), Xceed.Grid.Cell).ResetBackColor()
    Next
    SELECTEDCELLS.Clear()

    inCell = sender
    startX = inCell.ParentColumn.VisibleIndex

    Dim r As Xceed.Grid.DataRow
    Dim c As Xceed.Grid.Cell

    starty = Me.grdGRID.GetSortedDataRows(True).IndexOf(CType(inCell.ParentRow, Xceed.Grid.DataRow))
    End Sub

    Private Sub CellEdit(ByVal sender As Object, ByVal e As System.EventArgs)
    MOUSEDOWN = False
    End Sub

    Private Sub CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Dim inCell As Xceed.Grid.Cell
    Dim X As Integer
    Dim Y As Integer
    Dim tmp As Integer
    Dim newY As Integer
    Dim newX As Integer
    ‘Dim count As Integer
    Dim r As Xceed.Grid.DataRow
    Dim c As Xceed.Grid.Cell

    MOUSEDOWN = False

    inCell = sender

    newY = Me.grdGRID.GetSortedDataRows(True).IndexOf(CType(inCell.ParentRow, Xceed.Grid.DataRow))
    newX = inCell.ParentColumn.VisibleIndex

    ‘==========================

    ‘ Set startX/startY = lowest value

    ‘==========================
    If startX > newX Then
    tmp = startX
    startX = newX
    newX = tmp
    End If
    If starty > newY Then
    tmp = starty
    starty = newY
    newY = tmp
    End If

    For Y = starty To newY
    For X = startX To newX
    SELECTEDCELLS.Add(Me.grdGRID.GetSortedDataRows(True)(Y).Cells(X))
    Next
    Next

    For X = 0 To SELECTEDCELLS.Count – 1
    CType(SELECTEDCELLS(X), Xceed.Grid.Cell).BackColor = Me.BGColor
    Next

    End Sub

    Private Sub CellMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    If MOUSEDOWN Then
    Dim inCell As Xceed.Grid.Cell
    Dim X As Integer
    Dim Y As Integer
    Dim tmp As Integer
    Dim newY As Integer
    Dim newX As Integer
    Dim tmpStartX As Integer
    Dim tmpStartY As Integer
    Dim r As Xceed.Grid.DataRow
    Dim c As Xceed.Grid.Cell

    inCell = sender

    For X = 0 To SELECTEDCELLS.Count – 1
    CType(SELECTEDCELLS(X), Xceed.Grid.Cell).ResetBackColor()
    Next

    SELECTEDCELLS.Clear()

    tmpStartX = startX
    tmpStartY = starty

    newY = Me.grdGRID.GetSortedDataRows(True).IndexOf(CType(inCell.ParentRow, Xceed.Grid.DataRow))
    newX = inCell.ParentColumn.VisibleIndex

    ‘==========================

    ‘ Set startX/startY = lowest value

    ‘==========================
    If tmpStartX > newX Then
    tmp = tmpStartX
    tmpStartX = newX
    newX = tmp
    End If
    If tmpStartY > newY Then
    tmp = tmpStartY
    tmpStartY = newY
    newY = tmp
    End If

    For Y = tmpStartY To newY
    For X = tmpStartX To newX
    SELECTEDCELLS.Add(Me.grdGRID.GetSortedDataRows(True)(Y).Cells(X))
    Next
    Next

    For X = 0 To SELECTEDCELLS.Count – 1
    CType(SELECTEDCELLS(X), Xceed.Grid.Cell).BackColor = Me.BGColor
    Next

    End If
    End Sub

    ‘=======================================

    ‘ ChangeSelectedValues
    ‘ SDJXCEED

    Imported from legacy forums. Posted by DrWurm (had 901 views)

    User (Old forums)
    Member
    Post count: 23064

    Looks fine to me.

    Imported from legacy forums. Posted by Tommy (had 184 views)

    User (Old forums)
    Member
    Post count: 23064

    Actually, I just realized that the cell edit event isnt triggering. Any idea what event is called when a user enters “edit mode”?

    Imported from legacy forums. Posted by DrWurm (had 369 views)

    User (Old forums)
    Member
    Post count: 23064

    There are 2 possible events:
    – <b>EnteringEdit</b>: raised before editing a cell (gives you the option to cancel the editing)
    – <b>EditEntered</b>: raised when the cell has entered edit mode.
    I would use the 2nd one, if you don’t want the option to cancel the editing.

    Imported from legacy forums. Posted by Tommy (had 7632 views)

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.