countrymeister
asked on
display images in a datagridview column on a windows form
How do I display different images in a datagrid view. I have a windows form which has an image column called Indicator
I have a stored procedure which returns the image to display in a column called erp_image.
This column has the path to the image , example Images\red,gif
Under my root windows app I have folder called images, under which I have the respective images.
I am binding a dataset to the datagrid programmatically
example
ds = DBManager.getList(txtFromC al, txtToCal, txtStatus, txtClient, txtFilter);
dgView.DataSource = ds;
dgView.AutoGenerateColumns = false;
dgView.DataMember = "ERP";
Status.DataPropertyName = "ERP_STATUS";
Source.DataPropertyName = "ERP_SOURCE";
Indicator.DataPropertyName = "ERP_IMAGE";
I have a stored procedure which returns the image to display in a column called erp_image.
This column has the path to the image , example Images\red,gif
Under my root windows app I have folder called images, under which I have the respective images.
I am binding a dataset to the datagrid programmatically
example
ds = DBManager.getList(txtFromC
dgView.DataSource = ds;
dgView.AutoGenerateColumns
dgView.DataMember = "ERP";
Status.DataPropertyName = "ERP_STATUS";
Source.DataPropertyName = "ERP_SOURCE";
Indicator.DataPropertyName
ASKER
shahprabal,
The image column has to display different images based on the value of ERP_IMAGE.
I do have an image column but I need to bind an image at runtime
i have tried the following code and it works with an ImageList, but I loose the image when I sort on any column in the grid
DataGridViewCell valueCell = null;
DataGridViewImageCell displayCell = null;
for (int row = 0; row < dgView.Rows.Count; row++)
{
valueCell = dgView[IndicatorImage.Inde x, row];
displayCell = (DataGridViewImageCell)dgV iew[Indica tor.Index, row];
string n = (string)valueCell.Value;
//displayCell.Value = imageListIndicator.Images[ n];
if (n == "~/images/blueofms.gif")
displayCell.Value = imageListIndicator.Images[ 0];
else if (n == "~/images/greenofms.gif")
displayCell.Value = imageListIndicator.Images[ 1];
else if (n == "~/images/redofms.gif")
displayCell.Value = imageListIndicator.Images[ 2];
}
The image column has to display different images based on the value of ERP_IMAGE.
I do have an image column but I need to bind an image at runtime
i have tried the following code and it works with an ImageList, but I loose the image when I sort on any column in the grid
DataGridViewCell valueCell = null;
DataGridViewImageCell displayCell = null;
for (int row = 0; row < dgView.Rows.Count; row++)
{
valueCell = dgView[IndicatorImage.Inde
displayCell = (DataGridViewImageCell)dgV
string n = (string)valueCell.Value;
//displayCell.Value = imageListIndicator.Images[
if (n == "~/images/blueofms.gif")
displayCell.Value = imageListIndicator.Images[
else if (n == "~/images/greenofms.gif")
displayCell.Value = imageListIndicator.Images[
else if (n == "~/images/redofms.gif")
displayCell.Value = imageListIndicator.Images[
}
ASKER
I have the same problem where i loose the images and it displays a red x, when i sort on any grid column.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check out :
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewimagecolumn(VS.80).aspx