I'm trying to bring a SQL list and load it into a grid. After that, some fields of that grid must be of DataGridViewComboBoxColumn
, so that the user can select options according to the combos. This is the code that I have made:
public async void ConfigurarGrilla()
{
try
{
var responseArea = await servicio.AreaGetAllAsync();
var responseEmpresa = await servicio.EmpresaGetAllAsync();
if (responseArea.IsValid && responseEmpresa.IsValid)
{
listaArea = responseArea.Value;
listaEmpresa = responseEmpresa.Value;
dgvArticulos.AutoGenerateColumns = false;
DataGridViewComboBoxColumn dtColumn = dgvArticulos.Columns["CodArea"] as DataGridViewComboBoxColumn;
dtColumn.DataSource = listaArea;
dtColumn.DisplayMember = "CodArea";
DataGridViewComboBoxColumn dtColumn2 = (DataGridViewComboBoxColumn)dgvArticulos.Columns["RazonSocial"] as DataGridViewComboBoxColumn;
dtColumn2.DataSource = listaEmpresa;
dtColumn2.DisplayMember = "RazonSocial";
LoadDocumento();
}
else
{
MessageBox.Show(responseArea.ErrorMensaje);
}
}
catch (Exception ex)
{
MessageBox.Show("Ocurrio un error " + ex.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
The methods responseArea.Value
and responseEmpresa.Value
bring the list of the BD, which does contain information when I debug, but in the line dtColumn.DataSource = listaArea
is where I get the error
"object is not an object instance"
I do not know what the error could be, since I have not left any objects without instantiating.
Will anyone know what the possible error is?