Question

I have a datagridview with a DataGridViewComboboxColumn column with 3 values:

"Small", "Medium", "Large"

I get back the users default which in this case is "Medium"

I want to show a dropdown cell in the datagridview but default the value to "Medium". i would do this in a regular combobox by doing selected index or just stting the Text property of a combo box.

Was it helpful?

Solution

When you get into the datagridview it is probably best to get into databinding. This will take care of all of the selected index stuff you are talking about.

However, if you want to get in there by yourself,

DataGridView.Rows[rowindex].Cells[columnindex].Value 

will let you get and set the value associated to the DataGridViewComboBoxColumn. Just make sure you supply the correct rowindex and columnindex along with setting the value to the correct type (the same type as the ValueMember property of the DataGridViewComboBoxColumn).

OTHER TIPS

DataGridViewComboBoxColumn ColumnPage = new DataGridViewComboBoxColumn();
ColumnPage.DefaultCellStyle.NullValue = "Medium";

Are you retrieving the user data and attempting to set values in the DataGridView manually, or have you actually bound the DataGridVew to a data source? Because if you've bound the grid to a data source, you should just need to set the DataPropertyName on the column to be the string name of the object Property:

[DataGridViewComboboxColumnName].DataPropertyName = "PropertyNameToBindTo";

Or do you mean you want it to default to Medium for a new row?

Do accomplish this task you should do something like this:-

          this.dataGridViewStudentInformation.Columns[ColumnIndex].DataPropertyName = dataGridViewStudentInformation.Columns[2].Name ; //Set the ColumnName to which you want to bind.  

And set the default value in Database as Medium.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top