techno
techno

Reputation: 6500

Displaying Image in Devexpress DataGrid not working

I'm adding a new column to the Gridview using the following code

   GridColumn attachcolumn = new GridColumn() {

    Name = "TEST",
    FieldName = "TEST",
    UnboundType = DevExpress.Data.UnboundColumnType.Object,
    Caption = "TEST",
    //  ImageIndex = 0,
    ImageAlignment = StringAlignment.Center,
    ColumnEdit = new RepositoryItemPictureEdit(),
    //   ShowButtonMode = ShowButtonModeEnum.ShowOnlyInEditor
  };

  _gvSearchRes.Columns.Add(attachcolumn);

I'm setting the image like this

 for (int i = 0; i <= (_iDataRowCount - 1); i++)
  {
  _rgv.SetRowCellValue(i, "TEST", new Bitmap(10,10));
  }

The result i get is this.. The images are not displayed..Please advice enter image description here

Upvotes: 0

Views: 1081

Answers (1)

Dmitrii Babich
Dmitrii Babich

Reputation: 499

Your values are not displayed, because you are using an Unbound Column, but don't store your images anywhere. GridView doesn't save cell values itself. So, when you call the SetRowCellValue method, your images get lost. You need to store your unbound column values manually. To do this, handle the CustomUnboundColumnData event and save your images, for example, in a dictionary. Please refer to this example for a possible implementation.

Note that if you just need to show checkboxes, you don't need an unbound column. You can use RepositoryItemCheckEdit for this task. Set its ValueChecked property to "Yes" and ValueUnchecked property to "No". Then, assign this Repository Item to your column. As a result, you will see corresponding checkmarks in your column. If you wish, you can change the default image using the CheckBoxOptions property.

Upvotes: 1

Related Questions