Need a suggestion on a control

Pickle

Newcomer
Joined
Mar 1, 2006
Messages
18
I have a monitoring program that needs to display serial data (messages) in a list. Im not sure on the best form control to use.
Each message has different parts that I want to break up into multiple columns.
So the number of columns will be fixed, the rows could be on the order of 1000's. The rows need to be added on a realtime basis, but no faster than a rate of 3 ms. Not all data has to be seen, so a vertical scroll bar is needed.

Some controls Ive some across are flexgrid, or the .net datagrid (heard it was slow though). Right now im leaning on the flexgrid.

Any other ideas?
 
If you use

Visual Basic:
DataGrid.DataSoruce = MyArrayList/StronglyTypedCollection

the .NET Datagrid will not be slow; looping through each column and adding them manually

Visual Basic:
for x as integer = 0 to 100
   dg.columns("First").Add(x)
   dg.columns("Last").Add(x)
   dg.columns("custID").Add(x)
   dg.columns("phone").Add(x)
next x

it will be very slow.

The way I would do it is make a class or structure for the messages and populate an arraylist (good) or a strongly typed collection (better) and set the dg.datasoruce = to it.

Like this

Visual Basic:
Public Class Message
    Public Number as Integer
    Public Title as String
    Public Description as String
'you would want to do this better and use properties, etc
End Class

Then you would do something like this inside the loop you have to gather the message data

Visual Basic:
Dim AL as ArrayList

Do While...
    Dim myMessage as Message
    myMessage.Number = A number from your source
    myMessage.Title = Title from your source
    'etc with the other properties
    al.Items.Add(myMessage)
Loop

and then everytime you want to update the Datagrid do this

Visual Basic:
MyDataGrid.DataSource = Nothing
MyDataGrid.DataSource = AL

Hope This Helps
 
Great, i already have the class object with properties for the messages, although I did a list( of T) to group them? Will it make a difference using a arraylist instead?
 
Never mind, I did it with the array list and it looks good, the data is being populated.

What would be different with a strongly typed collection? I have not used one before.

Also is there any way to improve the refresh? Right now it has a flash from the entire control being redrawn. Is there a way to only draw the newest items?
 
Last edited:
Pickle said:
What would be different with a strongly typed collection? I have not used one before.
here's a link that talks a little of strongly typed collections
link

Pickle said:
Also is there any way to improve the refresh? Right now it has a flash from the entire control being redrawn. Is there a way to only draw the newest items?
well i'm no expert but have you tried beginupdate and EndUpdate methods?
 
I am not sure; possible these work in the same or similar way?

Visual Basic:
        DataGridView1.BeginEdit() 'Requires True/False Param
        DataGridView1.EndEdit()
 
Those appear to only apply to one row object

Im refreshing the gridview like you said with
Visual Basic:
MyDataGrid.DataSource = Nothing
MyDataGrid.DataSource = AL
Visual Basic:
    Sub Record_Class2Message(ByVal strDir As String, ByVal intData() As Integer)
        Dim Received_Message As New Class2_Message
        Dim totalbytes As Integer = intData(0) And &HF

        Received_Message.Type = strDir
        Received_Message.Header = Hex(intData(1)).PadLeft(2, "0"c) & " " & _
                                  Hex(intData(2)).PadLeft(2, "0"c) & " " & _
                                  Hex(intData(3)).PadLeft(2, "0"c)
        For index As Integer = 4 To totalbytes - 1
            Received_Message.Data &= Hex(intData(index)).PadLeft(2, "0"c) & " "
        Next
        Received_Message.Timestamp = Str((intData(totalbytes + 1) << 8) + intData(totalbytes + 2))

        Class2_Messages.Add(Received_Message)

        SetDataGridSource(Nothing) 'needed for mulithread
        SetDataGridSource(Class2_Messages) 'needed for mulithread
    End Sub

    ' This delegate enables asynchronous calls for setting
    ' the text property on a TextBox control.
    Delegate Sub SetDataGridSource_Callback(ByVal [data] As ArrayList)

    ' This method demonstrates a pattern for making thread-safe
    ' calls on a Windows Forms control. 
    '
    ' If the calling thread is different from the thread that
    ' created the TextBox control, this method creates a
    ' SetTextCallback and calls itself asynchronously using the
    ' Invoke method.
    '
    ' If the calling thread is the same as the thread that created
    ' the TextBox control, the Text property is set directly. 

    Private Sub SetDataGridSource(ByVal [data] As ArrayList)

        ' InvokeRequired required compares the thread ID of the
        ' calling thread to the thread ID of the creating thread.
        ' If these threads are different, it returns true.
        If Me.Class2DataGrid.InvokeRequired Then
            Dim d As New SetDataGridSource_Callback(AddressOf SetDataGridSource)
            Me.Invoke(d, New Object() {[data]})
        Else
            Me.Class2DataGrid.DataSource = [data]
            If Not [data] Is Nothing Then
                If Not [data].Count = 0 Then
                    Me.Class2DataGrid.CurrentRowIndex = [data].Count - 1
                End If
            End If
        End If
    End Sub
 
Last edited:
I just have to say that the data grid is totally useless as a control for adding data at a realtime speed. The redraw is too slow, I will probally have to use a listview and format the lines to appear to have columns.
 
Yes, cags is correct. You have to change the view property of the listview to details. You can also add columns from the designer if you wanted (but they will only be visible if the view is details or tile.
 
mskeel said:
Yes, cags is correct. You have to change the view property of the listview to details. You can also add columns from the designer if you wanted (but they will only be visible if the view is details or tile.

Actually I meant Listbox, but maybe you gave me a new solution. I will try it.
Is there a similar way to assign data like the gridview.datasource?
 
Last edited:
Cags said:
The ListView control has a DataSource property the same as the DataGrid I believe.

hmmm, I didnt see it in MSDN. I have seen a example using add range with a array of listviewitems.
 
Back
Top