Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am beginner to C#.

I need to create table for temp, voltage and current and this datab will be updating periodically by serial communication.


My query is, How to create a table in C# windows form which will update data dynamically. I do not want to extract data from any database.


Please suggest some sample code or controls to be used?


Thanks
Posted

1 solution

You need to combine three parts:

0) Get the data from a serial communication. If you mean an RS232-port to read the data from, you can use the SerialPort class[^].

1) Your data model. Create a custom class with properties that reflect the data you want to represent. Decode what you got from 0) and feed the data into your model.
[Edit]
A simple data model class:
C#
public class SingleDataPoint
{
    public decimal Temperature { get; set; }
    public decimal Voltage { get; set; }
    public decimal Current { get; set; }
}
This class has no logic in it. It's just for storing some values. Create an instance
C#
SingleDataPoint oneSingleData = new SingleDataPoint();
and fill in the values
C#
oneSingleData.Temperature = -273.15;
oneSingleData.Voltage = 42;
oneSingleData.Current = 0x0815;
If you need losts of those data points, keep them in a BindingList<SingleDataPoint>[^] for later easy binding to your UI.
[/Edit]

2) Display the data. Bind your model to a DataGridView[^] for automatic updating.
 
Share this answer
 
v2
Comments
[no name] 28-May-13 5:05am    
thanks for the reply. being newbie I am not getting how to proceed with model. I have done with 1# get the data from serial communication but NOT getting with how to add in table

Can you please send sample code for me
lukeer 28-May-13 5:46am    
I updated my answer. Hope it gets you started with the idea of custom classes.
[no name] 28-May-13 6:02am    
thanks a lot for explanation. I worked on 2 & 3 and now can view data table in form.

Thanks a lot
lukeer 28-May-13 6:14am    
I'm glad it works for you.
If you find my solution helpful, you can also rate it with some stars (the more the better)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900