Stock prices grid with blink

1 Answer 23 Views
GridView
aykut
Top achievements
Rank 1
aykut asked on 25 Jan 2022, 05:56 AM

I'm experimenting thia for almost one week. I almost read every post in forum and also other sources. problem is simle. I want to flash a grid cell when value changes. It works them column and row count is small but when grid is in fullscreen form with 20 columns and lets say 100 rows, cells sometimes blink, sometimes not. I noticed that when you decrease blink time it doenst work. when you go up to 150 ms and up it works. this tells me it has something todo with refresh rate or something. same problem exists with other solution approaches in forum.

Can I kindly ask you yo provide a working a flashing cell sample. I really tried to use every event, every suggestion in this forum.... and also its not first time I face the problem. Last year I had again and at the end I gave up and didnt use flashing function in my project. But this time I reaaly need this.

And also I should mention that this is a very common practice nowadays, so radgrid should able to handle that.

best.

' at the form load event..   
radGrid1.DataSource = sampleDataTable()
   
Private Function sampleDataTable() As DataTable
        Dim table1 = New DataTable("prices")
        table1.Columns.Add("id")
        table1.Columns.Add("Symbol")
        table1.Columns.Add("BuyPrice")
        table1.Columns.Add("MarketPrice")
        For i = 1 To 20
            table1.Columns.Add("Extra Column " & i)
        Next
        For i = 1 To 100
            table1.Rows.Add(i, "Stock A, "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10")
        Next
        Return table1
End Function
    
Private Sub radGrid1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles radGrid1.CellValueChanged

        radGrid1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Lime

        Dim t1 As Task = Task.Run(Sub()
                                      System.Threading.Thread.Sleep(180)
                                      radGrid1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = oldcolor
                                  End Sub)

End Sub
    

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

' change some random cells

        Dim r As Integer = random.Next(1, 10)
        Dim c As Integer = random.Next(1, 6)

        radGrid1.Rows(r).Cells(c).Value = Now.ToLongTimeString

End Sub
    

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jan 2022, 12:42 PM
Hello, Aykut,   


The CellValueChanged event is an appropriate way to detect when any cell gets updated. It is possible to style the updated cell in such a way that the modified cells will be easily distinguishable. One way to achieve it is the Style property that cell offers. The following help article demonstrates a sample approach:
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formating-examples/style-property

I have modified the provide code snippet and achieved the illustrated result below:

    Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        Me.RadGridView1.DataSource = sampleDataTable()
        Me.RadGridView1.BestFitColumns()

    End Sub

    Private Function sampleDataTable() As DataTable
        Dim table1 = New DataTable("prices")
        table1.Columns.Add("id")
        table1.Columns.Add("Symbol")
        table1.Columns.Add("BuyPrice")
        table1.Columns.Add("MarketPrice")
        For i = 1 To 20
            table1.Columns.Add("Extra Column " & i)
        Next
        For i = 1 To 100
            table1.Rows.Add(i, "Stock A", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", "10")
        Next
        Return table1
    End Function
     
    Private Sub radGrid1_CellValueChanged(sender As Object, e As GridViewCellEventArgs) Handles RadGridView1.CellValueChanged
         
        RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Lime
        RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.CustomizeFill = True
        RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.GradientStyle = Telerik.WinControls.GradientStyles.Solid

        Dim t1 As Task = Task.Run(Sub()
                                      System.Threading.Thread.Sleep(180)
                                      RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.CustomizeFill = False
                                  End Sub)

    End Sub

    Dim rand As New Random
    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        Dim r As Integer = rand.Next(1, 10)
        Dim c As Integer = rand.Next(1, 6)

        Me.RadGridView1.Rows(r).Cells(c).Value = Now.ToLongTimeString
    End Sub

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
aykut
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or