0
votes

I am having trouble implementing DataGridViewComboBoxCell inside the DataGridView control. What I want to do is to display in every row different set of choices – so each ComboBox has a different list to display. I am using Visual Studio designer.

I have assigned to myDataGridView.DataSource the BindingSource (variable name is bindingSourceComponenetFileInfo) to which DataSource (bindingSourceComponentFileInfo.DataSource) I have assigned my data called EclipseComponentFileInfo which is defined like this:

namespace EclipseSuiteMakerWindowsForms
{
    class EclipseComponentFileInfo
    {
        public EclipseComponentFileInfo()
        { }
        private string path;
        private string pathName;
        private string[] fileName;
        public string[] FileName { get => fileName; set => fileName = value; }
        public string Path { get => path; set => path = value; }
    }
}

The problem I am having is the ‘filename’ field – because it is not a plain string but an array of strings, it does not appear in Visual Designer under DataGridView/Columns/SelectedColumns (only PathName column is available). I used Visual Designer to create for my DataGridView an ‘Unbound column’ (which I still don’t quite understand what it is and how it works – no docs) specifying as ‘Name: FileName/Header text: FileNameHeader /Type:DataGridViewBoxColumn’ and then when I run my app, my ComboBox column in every row came up as an empty string – I kind of expected that.

So next I assigned (using Visual Designer) to the DataSource of the unbound column created above (DataGridViewBoxColumn.DataSource) variable (of type BindingSource) called fileNameBindingSource. Next I have assigned to ‘fileNameBindingSource .DataSource’, the earlier mentioned bindingSourceComponenetFileInfo (of type EclipseComponentFileInfo) with the DataPropertyName called FileName.

Then all rows’s ComboBox columns are filled with the name that appears in the first row for some reason.

My question is:

Can I have rows of ComboBox columns filled with different set of items or every ComboBox has to have the same set of items (e.g first row has ComboBox with array of one item “Item1”, but the second row has a comboBox with the array of two items “Item1/Item2”).

1

1 Answers

0
votes

The list of items doesn't come from the grid's data source. Generally speaking, you set a data source for the column and each cell inherits that. If you want a different list for each cell though, you need to set a different data source for each cell.