I have a picturebox in one form. When inserting data, I am filling the picturebox as well, together with other types objects, and on clikc on the picturebox I can open another window aith a whole picture of the document.
But when the data is inserted in the database, and I click on one row of the datagridview, all the objects are filled, and I want again when clicking on the picturebox to open the picture in a new window, but I get error.
"Object reference not set to an instance of an object."
in the bold row below.
The code for the form where I open the whole picture is:
public partial class Slik : Form
{
public Slik()
{
InitializeComponent();
Dogovor dog = (Dogovor)Application.OpenForms["Dogovor"];
DataGridView dgv = (DataGridView)dog.Controls["dataGridView2"];
byte[] data = (byte[])dgv.SelectedRows[0].Cells[3].Value;
MemoryStream ms = new MemoryStream(data);
pictureBox1.Image = Image.FromStream(ms);
}
private void Slik_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
}
and the code for the first form which calls this second form is:
private void pictureBox2_Click(object sender, EventArgs e)
{
if (pateka != "")
{
Slika slika = new Slika(izbranfajl);
slika.Show();
}
else
{
Slik slika1 = new Slik();
slika1.Show();
}
}
Can anybody help me please?Thank you in advance.
VulpesPosted Feb 22, 2012, 6:12 AM
NelPosted Feb 23, 2012, 1:35 AM
NelPosted Feb 22, 2012, 6:02 AM
VulpesPosted Feb 22, 2012, 5:05 AM
Is the DataGridView placed directly on your Dogovor form or is it on some other container such as a panel, groupbox or tabpage?
NelPosted Feb 22, 2012, 4:56 AM
But maybe it doesn't consider that any row is selected. When clicking on one row in the datagridview the values are retrieved and the combobox, datetimepicker, picturebox...are filled. And I want immediately to check the picture , so how can I open the picture when clicking on the picturebox in other way, or how to "repair" this one? Please tell me if you have any idea. Thanks
VulpesPosted Feb 22, 2012, 4:37 AM