change picture of image controll in gridvie in windows application???? [not solved yet...]
-
hi friends i have a datagridview and i add a column to this datagrid that has a picture(start symbol) i want to write a code that when a user click on the picture in datagridview the picture of that control has been changed (stop symbol). please tell me a solution and say me what code are usefull for this action
nobody help you... you have to help you yourself and this is success way.
modified on Thursday, October 8, 2009 1:32 PM
-
hi friends i have a datagridview and i add a column to this datagrid that has a picture(start symbol) i want to write a code that when a user click on the picture in datagridview the picture of that control has been changed (stop symbol). please tell me a solution and say me what code are usefull for this action
nobody help you... you have to help you yourself and this is success way.
modified on Thursday, October 8, 2009 1:32 PM
hi, its simple... add following html in the gridview column.
<a href="javascript:void(0);" onclick="ChangePic(this);"><img src="xyz.jpg"/></a>
now add a add following javascript to your page: function ChangePic(sender) { sender.childNodes[0].src="abc.jpg"; } there are many more ways to do this. Hope It solves ur problem... Regards Atif Ali Bhatti. -
hi, its simple... add following html in the gridview column.
<a href="javascript:void(0);" onclick="ChangePic(this);"><img src="xyz.jpg"/></a>
now add a add following javascript to your page: function ChangePic(sender) { sender.childNodes[0].src="abc.jpg"; } there are many more ways to do this. Hope It solves ur problem... Regards Atif Ali Bhatti. -
hi friends i have a datagridview and i add a column to this datagrid that has a picture(start symbol) i want to write a code that when a user click on the picture in datagridview the picture of that control has been changed (stop symbol). please tell me a solution and say me what code are usefull for this action
nobody help you... you have to help you yourself and this is success way.
modified on Thursday, October 8, 2009 1:32 PM
Is the column a bound column, or an unbound column.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Is the column a bound column, or an unbound column.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
no that is not a bound coloumn the column is used for showing to user the step of action such as start(show start symbol) or pause(show pause symbol) or stop(show stop symbol)..
nobody help you... you have to help you yourself and this is success way.
Then handle the
CellClick
event of theDataGridView
:private Bitmap start = new Bitmap("LocationForImage"); private Bitmap stop = new Bitmap("LocationForImage"); private void dataGridView1\_CellClick(object sender, DataGridViewCellEventArgs e) { // Try to load it as a DataGridViewImageCell DataGridViewImageCell img = dataGridView1.Rows\[e.RowIndex\].Cells\[e.ColumnIndex\] as DataGridViewImageCell // If that works, we have the right cell if (img != null) { if ((bool)img.Tag) { // if it is true then we are started, so stop img.Value = stop; img.Tag = false; // HERE DO ANYTHING ELSE REQUIRED FOR STOPPING e.g. this.timer1.Stop; } else { // if it is false then we are stopped, so start img.Value = start; img.Tag = true; // HERE DO ANYTHING ELSE REQUIRED FOR STARTING e.g. this.timer1.Start; } } }
This assumes that there is only one Image column. As you initially load the data into the image cells, you must set the
Tag
property to eithertrue
(start image used) orfalse
(stop image used) I hope that this helps. :)Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Then handle the
CellClick
event of theDataGridView
:private Bitmap start = new Bitmap("LocationForImage"); private Bitmap stop = new Bitmap("LocationForImage"); private void dataGridView1\_CellClick(object sender, DataGridViewCellEventArgs e) { // Try to load it as a DataGridViewImageCell DataGridViewImageCell img = dataGridView1.Rows\[e.RowIndex\].Cells\[e.ColumnIndex\] as DataGridViewImageCell // If that works, we have the right cell if (img != null) { if ((bool)img.Tag) { // if it is true then we are started, so stop img.Value = stop; img.Tag = false; // HERE DO ANYTHING ELSE REQUIRED FOR STOPPING e.g. this.timer1.Stop; } else { // if it is false then we are stopped, so start img.Value = start; img.Tag = true; // HERE DO ANYTHING ELSE REQUIRED FOR STARTING e.g. this.timer1.Start; } } }
This assumes that there is only one Image column. As you initially load the data into the image cells, you must set the
Tag
property to eithertrue
(start image used) orfalse
(stop image used) I hope that this helps. :)Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
thank you my friend for your reply your code run correctly but without any result and the image has not changed.!!!!
nobody help you... you have to help you yourself and this is success way.
Well I hadn't tested it although there was no reason that it shouldn't work, so I built a test app and it works exactly as I thought. Here is the code for the entire form:
public partial class ImageColumnTestForm : Form { private Bitmap start = ImageCellTest.Properties.Resources.START; // I am getting the images from the apps resources private Bitmap stop = ImageCellTest.Properties.Resources.STOP; // 'ImageCellTest' is the Namespace that I used. public ImageColumnTestForm() { InitializeComponent(); } private void ImageColumnTestForm\_Load(object sender, EventArgs e) { DataGridViewRow newRow = null; DataGridViewTextBoxCell textCell = null; DataGridViewImageCell imgCell = null; for (int i = 0; i < 5; i++) { newRow = new DataGridViewRow(); textCell = new DataGridViewTextBoxCell(); newRow.Cells.Add(textCell); imgCell = new DataGridViewImageCell(); newRow.Cells.Add(imgCell); textCell.Value = "Text " + i.ToString(); imgCell.Value = start; imgCell.Tag = true; this.dataGridView1.Rows.Add(newRow); } } private void dataGridView1\_CellClick(object sender, DataGridViewCellEventArgs e) { // Try to load it as a DataGridViewImageCell DataGridViewImageCell img = dataGridView1.Rows\[e.RowIndex\].Cells\[e.ColumnIndex\] as DataGridViewImageCell; // If that works, we have the right cell if (img != null) { if ((bool)img.Tag) { // if it is true then we are started, so stop img.Value = stop; img.Tag = false; // HERE DO ANYTHING ELSE REQUIRED FOR STOPPING e.g. this.timer1.Stop; } else { // if it is false then we are stopped, so start img.Value = start; img.Tag = true; // HERE DO ANYTHING ELSE REQUIRED FOR STARTING e.g. this.timer1.Start; } } } }
As you can see I simply copied the CellClick code from my previous reply to you and all that I changed was to add the semi-colon to the first line, as I am sure that you did. :-O This is just a standard form with a datagridview on it and it works just fine.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Well I hadn't tested it although there was no reason that it shouldn't work, so I built a test app and it works exactly as I thought. Here is the code for the entire form:
public partial class ImageColumnTestForm : Form { private Bitmap start = ImageCellTest.Properties.Resources.START; // I am getting the images from the apps resources private Bitmap stop = ImageCellTest.Properties.Resources.STOP; // 'ImageCellTest' is the Namespace that I used. public ImageColumnTestForm() { InitializeComponent(); } private void ImageColumnTestForm\_Load(object sender, EventArgs e) { DataGridViewRow newRow = null; DataGridViewTextBoxCell textCell = null; DataGridViewImageCell imgCell = null; for (int i = 0; i < 5; i++) { newRow = new DataGridViewRow(); textCell = new DataGridViewTextBoxCell(); newRow.Cells.Add(textCell); imgCell = new DataGridViewImageCell(); newRow.Cells.Add(imgCell); textCell.Value = "Text " + i.ToString(); imgCell.Value = start; imgCell.Tag = true; this.dataGridView1.Rows.Add(newRow); } } private void dataGridView1\_CellClick(object sender, DataGridViewCellEventArgs e) { // Try to load it as a DataGridViewImageCell DataGridViewImageCell img = dataGridView1.Rows\[e.RowIndex\].Cells\[e.ColumnIndex\] as DataGridViewImageCell; // If that works, we have the right cell if (img != null) { if ((bool)img.Tag) { // if it is true then we are started, so stop img.Value = stop; img.Tag = false; // HERE DO ANYTHING ELSE REQUIRED FOR STOPPING e.g. this.timer1.Stop; } else { // if it is false then we are stopped, so start img.Value = start; img.Tag = true; // HERE DO ANYTHING ELSE REQUIRED FOR STARTING e.g. this.timer1.Start; } } } }
As you can see I simply copied the CellClick code from my previous reply to you and all that I changed was to add the semi-colon to the first line, as I am sure that you did. :-O This is just a standard form with a datagridview on it and it works just fine.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
thank you man you see i try your code again in new project and work correctly then try to affect your code in main project but not work at all so i decide to create my datagridview and finally work correctly. i think that the problem was on visual studio not on your code or previose code that i used. thank you again.
nobody help you... you have to help you yourself and this is success way.