c# adding image to devexpress griditem

mion shion 241 Reputation points
2022-02-07T08:36:35.017+00:00

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. 171710-screenshot-2022-02-07-083232.png

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.

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Jose Antonio Gomez Souto 1 Reputation point
    2022-12-06T08:53:59.647+00:00

    You can handle GridView.CustomDrawCell event to draw any image in any cell.

    https://supportcenter.devexpress.com/ticket/details/t443394/how-to-draw-an-image-in-cells-depending-on-their-values

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.