|
-
Dec 23rd, 2005, 08:37 PM
#1
Thread Starter
Addicted Member
Datagrid real time update
I have an Excel workbook that receives real time data (updates every second) via a DDE link. I am trying to import this data into a vb.net datagrid. I can do that ok, except that my datagrid is static and the only way I can update it is to reload the workbook and refresh the datagrid. Since my worbook contains 1600 real time cells, it takes too long... maybe 5-10 seconds to read the data. Can someone give me some ideas on how to achieve a real time update in my datagrid as well?
This is my present code; I am refreshing it with a timer control:
Code:
Private Sub OpenDataGrid()
Dim dt As New DataTable
Dim dc As New DataColumn
Dim dr As DataRow
' Set up column headers
dt.Columns.Clear()
dt.Columns.Add("Symbol", Type.GetType("System.String"))
dt.Columns.Add("Date", Type.GetType("System.String"))
dt.Columns.Add("Time", Type.GetType("System.String"))
dt.Columns.Add("PrevClose", Type.GetType("System.String"))
dt.Columns.Add("Open", Type.GetType("System.String"))
dt.Columns.Add("High", Type.GetType("System.String"))
dt.Columns.Add("Low", Type.GetType("System.String"))
dt.Columns.Add("Last", Type.GetType("System.String"))
dt.Columns.Add("OI", Type.GetType("System.String"))
dt.Columns.Add("Change", Type.GetType("System.String"))
dt.Columns.Add("TradeVol", Type.GetType("System.String"))
dt.Columns.Add("DailyVol", Type.GetType("System.String"))
dt.Columns.Add("BidSize", Type.GetType("System.String"))
dt.Columns.Add("Bid", Type.GetType("System.String"))
dt.Columns.Add("Ask", Type.GetType("System.String"))
dt.Columns.Add("AskSize", Type.GetType("System.String"))
' Add Excel data to datatable row
Dim RowIndex As Integer = 0
Dim ColIndex As Integer = 0
For RowIndex = 2 To 101 ' In the future, read upper boundary
dr = dt.NewRow
ColIndex += 1
dr("Symbol") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Date") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Time") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("PrevClose") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Open") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("High") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Low") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Last") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("OI") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Change") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("TradeVol") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("DailyVol") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("BidSize") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Bid") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("Ask") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex += 1
dr("AskSize") = CStr(CType(xlWS.Cells(RowIndex, ColIndex), Excel.Range).Value)
ColIndex = 0
' Add row to datatable
dt.Rows.Add(dr)
' Bind datatable to the datagrid
dg.DataSource = dt
Next RowIndex
' Upon exit, release controls
dt = Nothing
dc = Nothing
dr = Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|