I bind image to GridView
from Resource folder.When I load that Form image will be bind.But When call that form from MDIPARENT
form Image will not be showed.I attach image and Code below.
DataGridViewImageColumn ic = new DataGridViewImageColumn();
ic.HeaderText = "Payment";
ic.Image = null;
ic.Name = "cImg";
ic.Width = 50;
dtGrCustBal.Columns.Add(ic);
foreach (DataGridViewRow row in dtGrCustBal.Rows)
{
DataGridViewImageCell cell = row.Cells[10] as DataGridViewImageCell;
cell.Value = Properties.Resources.icon_payment_cash_small;
}
CustomerBalance ChildCustBal = new CustomerBalance();
ChildCustBal.MdiParent = this;
ChildCustBal.Show();
Loading from MDI parent: Loading directly:
To display a picture at design timeIn the Properties window, select the Image property, then select the ellipsis button to display the Open dialog box. If you're looking for a specific file type (for example, . gif files), select it in the Files of type box. Select the file you want to display.
When the image is bound in the form load event handler, in case of MDIChild
the value of the DataGridViewImageCell
is again reset to null by the time form is shown and you don't see any image. When its not MDChild
then the cell value is retained and you see the image. I am not clear why the reset is happening in case of MDIChild
.
Subscribe to the form's Shown
event and move your image binding code to that event handler. It works in both normal and MDIchild
use cases.
Try this, Use your project Namespace, when retrieving the image from Resource Folder.
DataGridViewImageColumn ic = new DataGridViewImageColumn();
ic.HeaderText = "Payment";
ic.Image = null;
ic.Name = "cImg";
ic.Width = 50;
dtGrCustBal.Columns.Add(ic);
foreach (DataGridViewRow row in dtGrCustBal.Rows)
{
DataGridViewImageCell cell = row.Cells[10] as DataGridViewImageCell;
cell.Value ="your namespace".Properties.Resources.icon_payment_cash_small;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With