I am new here and startig to learn C#. Before I programed in C and Windows.Forms in VBA. Now I have a Project where I receive serial port data from a device, that sends the contents of various C-structs (some nested). I want to display these Datasets in Windows.Forms each labeled, edit the values and send it back to the device. So it can easily copy the received data into its structures. Now I don't know an easy way to get the structured data inside a c#-byte-list into various text boxes(?) that have describing labels to it. I would like to design the layout in Form Designer, so not want to create the controls dynamically. But maybe this is the best way? Does someone know a good strategy / a best suited control to achieve this? Thanks in advance.
-
It's really hard to do Windows Forms in VBA. Did you mean VB.NET? – Enigmativity Apr 18 '22 at 00:00
-
1You really need to try something and ask us specific question about that when you get stuck. If you're asking us for strategy or design or controls, etc, then you're likely to get confusing answers. – Enigmativity Apr 18 '22 at 00:02
1 Answers
You could use a DataGridView
with control buttons inside each row or external buttons that handle selected row(s). In order to see and change the details a corresponding dialog form comes in handy in which I would implement a hex editor with the byte/hex values on the left and the readable value on the right.
To display the byte data just convert it to a hexadecimal string so you can display it in one column inside the DataGridView
.
For the nesting part, you could either implement child elements inside the DataGridView
itself (you need to either code this yourself or use some 3rd party extensions like this or Telerik, e.g., which also has the possibility of including button columns) or open a conditional dialog form which again shows a DataGridView for the child elements and so on (so you would open the same form as child form ad infinitum).
Thereby you are as flexible as possible and do not rely on fixed text box elements which you have to add or extend on further information.

- 156
- 2
- 13
-
2Be wary of answering questions like "how should I design...?" - it's usually opinion based and hard to judge answers as objectively correct – Caius Jard Apr 17 '22 at 20:58
-
OK, thanks for that hint. I didn't use the data grid before. So I have to study that control deeply to figure out how to feed the data grid from my receiver-list. – Elektrolurch Apr 17 '22 at 21:33