0

I just need a standard day of the week combobox drop down in 7 columns in my DataGridView for my users to selected days of week , my initial solution was to edit the columns of the DataGridView and set the ColumnType to DataGridViewComboBoxColumn and manually add the days of the week items to the collection.

I then ran it and the bound data autoselected the proper day and displayed it in the cell, clicking on the cell did nothing. Then I researched that and someone said you needed to change the ReadOnly from true to false, when I tried that it worked in the "Edit Columns" dialog and saved, "OK!!" I thought... Microsoft has its stuff together and I don't need to write code for this incredibly simple thing, but after running this the click on the drop downs in my grid STILL did nothing, then after I went back and checked my ReadOnly property only to find it had been reset back to True.

I have seven columns that accept day of the week data do I need to create a datasource with the days of the week in it and then bind each combobox? seems like an easy task made incredibly difficult.

Any help please

Lyle
  • 419
  • 1
  • 6
  • 26

1 Answers1

2

Are you looking for a new row on each input? You might want to use the Design pages properties instead of coding it. I couldn't clearly understand what you are looking for. Also is this Winforms?

    private void Form1_Load(object sender, EventArgs e)
    {
        for(int i = 0; i < 7; i++)
        {
            dataGridView1.Columns.Add(CreateComboBoxDayColumn((i + 1).ToString()));
        }
    }

    private DataGridViewComboBoxColumn CreateComboBoxDayColumn(string headerText) => 
        new DataGridViewComboBoxColumn
        {
            HeaderText = headerText,
            DropDownWidth = 160,
            Width = 90,
            MaxDropDownItems = 7,
            FlatStyle = FlatStyle.Flat,
            Items =
            {
                "Sunday",
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday",
                "Saturday",
            }
        };
Tim
  • 170
  • 10