Home - Forums-.NET - FlyGrid.Net (Windows Forms) - No row when scroll down

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

No row when scroll down
Link Posted: 16-Dec-2010 01:44
When i tried to scroll down, is seems that the row data is blank or invisible. Pls help.


Imports NineRays.Windows.Forms.Grids
Imports NineRays.Windows.Forms.Data

Public Class Form1
    Shared Test As DataTable = Data()

    Private Sub Start_Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start_Btn.Click
        Dim arr1 As DataTable = Test

        FlyGrid1.BeginInit()
        Try
            Dim i As Integer
            'Add columns
            For i = 0 To arr1.Columns.Count - 1
                Dim dc As DataColumn = arr1.Columns(i)
                Dim col As Column = New Column(dc.Caption, dc.ColumnName)
                ' add new column
                FlyGrid1.Columns.Items.Add(col)
            Next i
            ' connect to a data table
            FlyGrid1.Rows.DataSource = arr1
        Finally
            FlyGrid1.EndInit()
        End Try

        BackgroundWorker1.RunWorkerAsync()

    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

        While Not BackgroundWorker1.CancellationPending

            ' Add row dt
            Dim dr_new As DataRow
            dr_new = Test.NewRow
            dr_new.Item("Col1") = "Col1"
            dr_new.Item("Col2") = "Col2"
            dr_new.Item("Col3") = "Col3"
            dr_new.Item("Col4") = "Col4"
            dr_new.Item("Col5") = "Col5"
            dr_new.Item("Col6") = "Col6"
            dr_new.Item("Col7") = "Col7"
            dr_new.Item("Col8") = "Col8"
            dr_new.Item("Col9") = "Col9"
            dr_new.Item("Col10") = "Col10"
            dr_new.Item("Col11") = "Col11"
            dr_new.Item("Col12") = "Col12"
            dr_new.Item("Col13") = "Col13"
            dr_new.Item("Col14") = "Col14"
            dr_new.Item("Col15") = "Col15"
            dr_new.Item("Col16") = "Col16"
            dr_new.Item("Col17") = "Col17"
            dr_new.Item("Col18") = "Col18"
            dr_new.Item("Col19") = "Col19"
            dr_new.Item("Col20") = "Col20"
            Test.Rows.Add(dr_new)

            BackgroundWorker1.ReportProgress(0, "test")

            System.Threading.Thread.Sleep(500)
        End While


    End Sub

    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        FlyGrid1.BeginInit()
        Try
            FlyGrid1.Refresh()
        Finally
            FlyGrid1.EndInit()
        End Try

    End Sub

    Private Sub Cancel_Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Btn.Click
        BackgroundWorker1.CancelAsync()
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        MsgBox("Cancelled")
    End Sub

    Public Shared Function Data() As DataTable
        Dim dt As New DataTable

        dt.Columns.Add("Col1")
        dt.Columns.Add("Col2")
        dt.Columns.Add("Col3")
        dt.Columns.Add("Col4")
        dt.Columns.Add("Col5")
        dt.Columns.Add("Col6")
        dt.Columns.Add("Col7")
        dt.Columns.Add("Col8")
        dt.Columns.Add("Col9")
        dt.Columns.Add("Col10")
        dt.Columns.Add("Col11")
        dt.Columns.Add("Col12")
        dt.Columns.Add("Col13")
        dt.Columns.Add("Col14")
        dt.Columns.Add("Col15")
        dt.Columns.Add("Col16")
        dt.Columns.Add("Col17")
        dt.Columns.Add("Col18")
        dt.Columns.Add("Col19")
        dt.Columns.Add("Col20")

        Return dt
    End Function



End Class



Link Posted: 17-Dec-2010 22:06
Thanks for your question and sample.
Please make modifications to your code to optimize it and get work correctly:
1. Procedure BackgroundWorker1_DoWork - please add Test.AcceptChanges()when row is added, to notify table about changes (and consequently notify FlyGrid that Datasource is changed):
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    While Not BackgroundWorker1.CancellationPending            
        ' Add row dt
        Dim dr_new As DataRow
        dr_new = Test.NewRow
        dr_new.Item("Col1") = "Col1"
        dr_new.Item("Col2") = "Col2"
        dr_new.Item("Col3") = "Col3"
        dr_new.Item("Col4") = "Col4"
        dr_new.Item("Col5") = "Col5"
        dr_new.Item("Col6") = "Col6"
        dr_new.Item("Col7") = "Col7"
        dr_new.Item("Col8") = "Col8"
        dr_new.Item("Col9") = "Col9"
        dr_new.Item("Col10") = "Col10"
        dr_new.Item("Col11") = "Col11"
        dr_new.Item("Col12") = "Col12"
        dr_new.Item("Col13") = "Col13"
        dr_new.Item("Col14") = "Col14"
        dr_new.Item("Col15") = "Col15"
        dr_new.Item("Col16") = "Col16"
        dr_new.Item("Col17") = "Col17"
        dr_new.Item("Col18") = "Col18"
        dr_new.Item("Col19") = "Col19"
        dr_new.Item("Col20") = "Col20"
        Test.Rows.Add(dr_new)
        Test.AcceptChanges()
      'BackgroundWorker1.ReportProgress(0, "test")      
      System.Threading.Thread.Sleep(500)
    End While
  End Sub

2. Now you don't need to use ProgressChanged event (and BackgroundWorker1_ProgressChanged event handler), because FlyGrid will be notified about chnages and will update rows automatically.