I want to display data in a windows form using C# .NET. So that’s good, there are many ways to do that. The data is coming in as a flat text file. Some of the data should be displayed as a single element that stretches across the control (a comment line), while other data should be displayed in a table with many columns. Yet, I want the whole list, including comments, to be displayed in one single list.
My problem is that at this point I am not sure what control I should/could use to display this irregular data, or what approach I should take. What would part of the c# forms controls should I be learning about and planning to use in order to fill my goals. My current candidates are vacillating between ListView and DataGridView. What tool(s) can be used to fill this need where some table rows will be a single column and others will be multiple columns, if any.
Lets say my data looks like this:
red | green | purple | blue
comment that is one single piece of data
Foo----------------- | Bar---------------
red-------| green--- | purple-- | blue
one | green | purple | blue
Foo----------------- | Bar---------------
one | two | three | four
comment that is one single piece of data
comment that is one single piece of data
red | green | purple | blue
one | green | purple | blue
Foo----------------- | Bar---------------
one | two | three | four
It would be very helpful to see the structure of your data. What in the world is a "unified comment - list"? What do you mean by "irregular data"?
Anyway, in my experience, the best tool in Winforms to deal with tabular data is DataGridView
. You can have combobox cells, image cells. You can easily format and color them, validate and disable when necessary.
Edit: more info
What you need is basically some colspan, easibly obtainable in HTML grids. You can't do that easily in DataGridView, quoting the Ms DataGridView program manager
The DataGridView does not have any support for merging cells. You can custom paint
content across cells, but apart from that you would have to do a lot of work and
custom coding to produce merged editable cells.
but you could buy a 3rd party component (Telerik GridView or similar) or search for a custom implementation like this:
DataGridVewTextBoxCell with Span Behaviour
Maybe this can be useful too:
Multi Column Combo Cell for the .NET 2.0 DataGridView Control
EDIT 3: Ok, if you just need to display your data why don't you try adding in your winform a webBrowser
component, compose your HTML text and then display it? You can add style, font, colors etc etc like any web page.
Sample
private void showHtml()
{
var htmlstring = @"<html><table border='1'>
<tr>
<td>Red</td>
<td>Green</td>
<td>Purple</td>
<td>Blue</td>
</tr>
<tr>
<td colspan='4'>Comment that is one single piece of data</td>
</tr>
<tr>
<td colspan='2'>Foo</td>
<td colspan='2'>Bar</td>
</tr>
<tr>
<td>Red</td>
<td>Green</td>
<td>Purple</td>
<td>Blue</td>
</tr>
<tr>
<td>Red</td>
<td>Green</td>
<td>Purple</td>
<td>Blue</td>
</tr>
<tr>
<td colspan='4'>Comment that is one single piece of data</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
</table>
</html>";
webBrowser1.DocumentText = htmlstring;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments