Is it possible to allow more than one object in a cell in a DataGridView?
I want to display a Group in the first column and then in the column next to it I want to display all of the users that are in that group but in one cell (the cell next to the group name). And this can not be string manipulation because I need to be able to click on each of the users and drag and drop them around. I am using a DataGridview linked up to a SQL query database.
I am using Visual Basic with Visual Studio 2010.
Unfortunately you cannot do this in the DataGridView. You can, however, create a table that looks something like this:
Once you do this, then you can handle the
CellFormattingevent of the DataGridView and set thee.FormattedValuetoString.Emptyif the value of the cell above matches. Then your table will “look” like:This is pretty much what you are looking for. If you want the gridlines to go away, you can instead handle the DataGridView’s
CellPaintingevent to draw proper borders, center text, etc.UPDATE: Here’s an example of using the CellFormatting event to hide the contents of a cell. In this example, I am just using a List as my datasource, but you can substitute this for your SQL Data Source, DataTable, etc.