You can handle GridView.CustomDrawCell event to draw any image in any cell.
c# adding image to devexpress griditem
good morning all, have a quick question -
so i am trying to add a image to a grid cell and having issue with it telling me -
System.NullReferenceException: 'Object reference not set to an instance of an object.'
DevExpress.XtraGrid.Columns.GridColumnCollection.this[string].get returned null.
code i have is here,
if (File.Exists(songs.COL_Filename))
{
RepositoryItemTextEdit te = new RepositoryItemTextEdit();
gridControl1.RepositoryItems.Add(te);
//gridView1.Columns["Col_Artist"].ColumnEdit = te; // test 32 - try adding col artist see if index numbers are setup.
gridView1.Columns["Col_Error"].ColumnEdit = te;
Image myImage = Resources.apply_32x32;
te.ContextImage = myImage;
}
else
{
RepositoryItemTextEdit te = new RepositoryItemTextEdit();
gridControl1.RepositoryItems.Add(te);
gridView1.Columns["Col_Error"].ColumnEdit = te;
Image myImage = Resources.cancel_32x32;
te.ContextImage = myImage;
}
but the issue i have is its telling me that
gridView1.Columns["Col_Error"].ColumnEdit = te;
is a null refrence.
how i have the column setup.
as you can see from the image above highlighted the column and name and that reflects perfect to the code.
if i change the Col_Error - to 3 value it works pefectly however i dont want to use it by index as i will be adding a data binding to it later on in development so it will change and not consistent. this did used to work perfectly before i updated vs to 2022.