0

I have some data that I am currently implementing the presentation of in a Windows.Forms.DataGridView. I am questioning if DataGridView is the best component to use and if not, what component is.

The image below shows how the data is to be presented. The first 2 columns are static. The 3rd column is data entered by the user. The reason I think that DataGridView may not be appropriate is that there a 2 kinds of rows. The first kind has a Group and nothing in the Item and Grower columns. The second kind has nothing in Group, always has an Item, and may or may not have a Grower.

Is DataGridView the best component for this? If so, how would a BindingSource be defined?

DataGridView

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
  • 1
    Try taking a look at this question, its related but since you are asking about a specific implementation I don't really consider it a duplicate, could still be helpful in your search though. http://stackoverflow.com/questions/2493003/what-are-the-alternatives-to-datagridview – RH6 May 04 '17 at 15:09
  • 2
    I think GridView is fine with Merge cells: http://stackoverflow.com/questions/16774966/how-to-merge-datagridview-cell-in-winforms – Mohit Vashistha May 04 '17 at 15:12
  • @RH6: I had seen this (probably should have mentioned that in the question). Not really what I'm looking for. – Al Lelopath May 04 '17 at 15:16
  • @Mohit: that may help, thanks. – Al Lelopath May 04 '17 at 15:16
  • 1
    As [Christopher proposed](http://stackoverflow.com/a/43789104/3773066), use `ListView.Groups`. Suggested reading: ([1](http://www.c-sharpcorner.com/uploadfile/853a6a/grouping-listview-items-dynamically/), [2](http://csharphelper.com/blog/2014/08/use-listview-groups-in-c/), and especially [3](http://www.kettic.com/winforms_ui/csharp_guide/listview_feature_grouping.shtml)) – OhBeWise May 04 '17 at 17:44
  • @OhBeWise: Thanks, the link you give in [2](http://csharphelper.com/blog/2014/08/use-listview-groups-in-c/) is the key. Also, this question has been marked as "primarily opinion-based" which is just wrong. ListView is clearly the component to use in this case, not DataGridView. – Al Lelopath May 05 '17 at 13:07

1 Answers1

2

If I was you, I would instead try implementing this with a ListView control. Set up two columns in it corresponding to the last two columns of your DataGridView implementation (Item and Grower), and use the Groups property to set up actual groups for each of your entries under your first (Group) column. This should use your available space much more efficiently.

Knowledge Cube
  • 990
  • 12
  • 35