Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update DataGrid in another form

Status
Not open for further replies.

wtfia2k

ISP
Jun 20, 2005
5
DE
Hi everyone,
do you remember ALF? "Stuck on earth" - that's the way I'm feeling.

What I want to do is update the datagrid with the new values I got from this Sub (handled by a timer):

Code:
Private Sub HandlefrmStatus(ByVal aEvents As Array, ByVal bFirstRun As Boolean)
        Dim iClear As Decimal
        Dim i, j As Integer

        Dim ds As New DataSet
        Dim tbl As New DataTable("EVENTS")
        Dim col As DataColumn
        Dim row As DataRow

        ds.Tables.Add(tbl)
        col = tbl.Columns.Add(" ")

        For i = 1 To aEvents.GetUpperBound(1)
            col = tbl.Columns.Add(aEvents(0, i))
        Next i

        For i = 1 To aEvents.GetUpperBound(0)
            row = tbl.NewRow()
            For j = 0 To aEvents.GetUpperBound(1)
                row(j) = aEvents(i, j)
            Next j
            tbl.Rows.Add(row)
        Next i

        frmStatus.DataGrid1.DataBindings.Clear()
        frmStatus.DataGrid1.SetDataBinding(ds, "EVENTS")

        frmStatus.Opacity = 0
        frmStatus.Refresh()
        frmStatus.Visible = True

        If frmStatus.Opacity < 1 Then
            'we fade in
            For iClear = 0 To 1 Step 0.001
                frmStatus.Opacity = iClear
            Next
        End If

    End Sub

In the second run I get a "no value for index 0".
What am I doing wrong?

Thanks for your help.

wtfia2k

 
Rather than reassigning the grids datasource, why dont you simply pass the EVENTS Table by reference into your Sub


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Thank you SqueakinSweep.
But I'm not sure if we're talking about the same thing.
I'll try to clarify:

Code:
Private Sub tPollFired(ByVal Source As Object, ByVal e As System.Timers.ElapsedEventArgs)
        ReadEvents(False)
    End Sub

ReadEvents builds an array and calls HandlefrmStatus with this array.
In another form, called frmStatus, exists a Datagrid, who's data should be updated, every time (15 seconds) tPollFired is fired.

Do I have an error by design?
Maybe a code-snippet could clarify my confusion?

Thanks for your help.

wtfia2k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top