Pickle Posted March 1, 2006 Posted March 1, 2006 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? Quote
Nate Bross Posted March 1, 2006 Posted March 1, 2006 If you use DataGrid.DataSoruce = MyArrayList/StronglyTypedCollection the .NET Datagrid will not be slow; looping through each column and adding them manually 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 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 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 MyDataGrid.DataSource = Nothing MyDataGrid.DataSource = AL Hope This Helps Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Pickle Posted March 2, 2006 Author Posted March 2, 2006 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? Quote
Pickle Posted March 2, 2006 Author Posted March 2, 2006 (edited) 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? Edited March 2, 2006 by Pickle Quote
rfazendeiro Posted March 2, 2006 Posted March 2, 2006 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 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? Quote
Pickle Posted March 2, 2006 Author Posted March 2, 2006 There are no beginupdate/endupdate methods for this control Quote
Nate Bross Posted March 2, 2006 Posted March 2, 2006 I am not sure; possible these work in the same or similar way? DataGridView1.BeginEdit() 'Requires True/False Param DataGridView1.EndEdit() Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Pickle Posted March 2, 2006 Author Posted March 2, 2006 (edited) Those appear to only apply to one row object Im refreshing the gridview like you said with MyDataGrid.DataSource = Nothing MyDataGrid.DataSource = AL 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 Edited March 2, 2006 by Pickle Quote
Pickle Posted March 6, 2006 Author Posted March 6, 2006 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. Quote
Cags Posted March 6, 2006 Posted March 6, 2006 What do you mean by 'format the lines to appear to have columns'? The ListView control supports columns. Quote Anybody looking for a graduate programmer (Midlands, England)?
mskeel Posted March 7, 2006 Posted March 7, 2006 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. Quote
Pickle Posted March 7, 2006 Author Posted March 7, 2006 (edited) Yes' date=' 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? Edited March 7, 2006 by Pickle Quote
Cags Posted March 7, 2006 Posted March 7, 2006 The ListView control has a DataSource property the same as the DataGrid I believe. Quote Anybody looking for a graduate programmer (Midlands, England)?
Pickle Posted March 8, 2006 Author Posted March 8, 2006 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. Quote
Cags Posted March 8, 2006 Posted March 8, 2006 Your correct, I was thinking of a ListBox. As you say it can be done using the AddRange() method. Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.