Changing the Value of a Cell

Apr 8, 2011 at 8:29 PM

I'm trying to get my program to monitor for cell changes and when the value is changed, format the text and put it in the cell.  During initial setup of the control I have:

QueryGrid.Controller.AddController(ValueChangedController)

Where ValueChangedController is defined as:

Dim ValueChangedController As ValueChangedEvent = New ValueChangedEvent

Now the actually code in the ValueChangedEvent class is:

Public Class ValueChangedEvent
    Inherits SourceGrid.Cells.Controllers.ControllerBase

    Public Overrides Sub OnValueChanged(ByVal sender As SourceGrid.CellContext, ByVal e As System.EventArgs)
        MyBase.OnValueChanged(sender, e)

        If sender.Position.Row >= 4 Then
            Dim criteria As String
            If sender.Value IsNot Nothing Then
                criteria = sender.Value.ToString
                criteria = FormatCriteria(criteria)
                sender.Value = criteria
            End If
        End If

        sender.Grid.AutoSizeCells()
    End Sub

    Private Function FormatCriteria(ByVal criteria As String) As String

        criteria = criteria.Trim
        If criteria.ToLower.Contains("like") Then
            Dim lastpart As String = criteria.Substring(4, criteria.Length - 4)
            lastpart = lastpart.Trim
            Return "LIKE " & Chr(34) & lastpart & Chr(34)
        ElseIf criteria.Contains("=") Then
            Dim div() As String
            div = criteria.Split("=")
            Return "=" & Chr(34) & div(1) & Chr(34)
        ElseIf String.IsNullOrEmpty(criteria) Then
            Return String.Empty
        Else
            Return Chr(34) & criteria & Chr(34)
        End If

    End Function
End Class

The problem is that the line

 

sender.Value = criteria

does not replace the text that is already in the cell.  Everything else works fine; it pulls the data from the correct cells, formats it properly, returns the correct data, it just does not replace the unformatted text in the cell with the new formatted text.  I'm assuming this has something to do with the fact that the sender is a VirtualCell.  I'm pretty new to SourceGrid (only been using it two days) so I would greatly appreciate any help in getting this to work.  Thanks in advance.

 

Dominick