Я пытаюсь установить значение комбинированного списка динамически из запроса со следующим кодом, и оно отображается, только когда я щелкаю по столбцу комбинированного списка, если я не нажимаю, значение исчезает и не устанавливается.
Первые 5 значений относятся к пользователю, и значение, отображаемое в поле со списком, может быть не задано в базе данных, поэтому оно может быть нулевым, если его не существует, или ввести «A» или «C».
Это изображение перед нажатием на ячейку ![enter image description here](https://i.stack.imgur.com/UEl4a.png)
Это изображение после нажатия на ячейку с загруженными данными ![enter image description here](https://i.stack.imgur.com/mxkFN.png)
Это изображение после того, как ячейка снята и выбрана любая другая ячейка
![enter image description here](https://i.stack.imgur.com/UEl4a.png)
//This code is used to Build combobox column after the data is binded
var items = new[] { new Logica.Items { valor = "C", texto = "Creador" }, new Logica.Items { valor = "A", texto = "Aprobador" } };
DataGridViewComboBoxColumn cell = new DataGridViewComboBoxColumn();
cell.DataSource = items;
cell.ValueMember = "valor";
cell.DisplayMember = "texto";
this.dataGridView1.Columns.Insert(5, cell);
this.dataGridView1.Columns[5].HeaderText = "TipoUsuario";
for (int i = 0; i < this.dataGridView1.RowCount; i++)
{
string valor = dataGridView1[0, i].Value.ToString();//get the first datagridview value
if (valor != null || valor != "")
{
string orgv = string.Empty + this.dataGridView1[0, i].Value.ToString().ToUpper();//required to fill combobox conditions
string veg = string.Empty + this.dataGridView1[1, i].Value.ToString().ToUpper();//required to fill combobox conditions
string aprobador = string.Empty + this.dataGridView1[3, i].Value.ToString().ToUpper();//required to fill combobox conditions
DataTable ds = cargarnodos("LLenaTipoUsuario"); // this query into db to get the combobox values if this exists, if not then it's null.
foreach (DataRow datar in ds.Rows)
{
if (orgv == datar["VKORG"].ToString() && veg == datar["VTWEG"].ToString() && aprobador == datar["idAprobador"].ToString())
{
string seleccion = datar["TipoUsuario"].ToString().ToUpper();
this.dataGridView1[5, i].Value = seleccion; // this changes value
MessageBox.Show(dataGridView1[5, 0].Value.ToString());
break;
}
}
}