Hello again,
This time I'm trying to fill a form with values from datagrid when user clicks on Row.
Everything is working, except if values are null in Database.
So, here's my CellClick Event:
private void data_CellClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e)
{
int rowIndex = e.DataRow.RowIndex;
var recordIndex = data.TableControl.ResolveToRecordIndex(rowIndex);
var record1 = data.View.Records.GetItemAt(recordIndex);
var ID = data.Columns[0].MappingName;
var Anomalia = data.Columns[1].MappingName;
var Descricao = data.Columns[2].MappingName;
var DataC = data.Columns[3].MappingName;
var Comentarios = data.Columns[4].MappingName;
DetailID = Convert.ToInt32(record1.GetType().GetProperty(ID).GetValue(record1, null));
CmbAnomalia.Text = record1.GetType().GetProperty(Anomalia).GetValue(record1, null).ToString();
TxtDescAnomalia.Text = record1.GetType().GetProperty(Descricao).GetValue(record1, null).ToString() ?? null;
DataCorrecao.Value = (DateTime?)record1.GetType().GetProperty(DataC).GetValue(record1, null);
//This is where I get Error (Object not set to an instance of an object
//But if there's no value in database (instead of NULL), I get no error
TxtComentarios.Text = record1.GetType().GetProperty(Comentarios).GetValue(record1, null).ToString() ?? null;
}
Any workaround to avoid "Object not set to an instance of an object error?
Thanks