Search code examples
c#datagridviewrowpicturebox

how to add a picturebox image to datagridview without using a refresh of grid?


So i'm trying to add an picturebox image to datagridview without having a refresh method of my datagridview and without sql intervention so just add a picturebox image in a datagridview thats it, i already managed to press in a row and that picture box image that is in the row shows in a picturebox outside the datagridview now i need the opposite : i need something simple and clear like string tenthcolumn = pictureBox2.Image;

        private void AddARow(DataTable table)
    {
        // Use the NewRow method to create a DataRow with 
        // the table's schema.
        // Add the row to the rows collection.
        string firstColum = textBox1.Text;
        string secondColum = textBox2.Text;
        string thirdColum = textBox3.Text;
        string fourthColum = textBox4.Text;
        string dateColum = dateTimePicker1.Value.ToShortDateString();
        string fifthColum = comboBox2.Text;
        string sixthColum = comboBox3.Text;
        string seventhColumn = comboBox4.Text;
        string eighthColumn = comboBox5.Text;
        string ninethcolumn = textBox5.Text;
        
        string tenthcolumn = pictureBox2.Image;//this

        string[] row = { firstColum, secondColum, thirdColum, fourthColum, dateColum, fifthColum, sixthColum,seventhColumn,eighthColumn,ninethcolumn,tenthcolumn  };

        table.Rows.Add(row);
    }

Solution

  • i found while asking the question lol, by the way i was using a datatable : add using system.io;

            private void AddARow(DataTable table)
        {
            // Use the NewRow method to create a DataRow with 
            // the table's schema.
            // Add the row to the rows collection.
            string firstColum = textBox1.Text;
            string secondColum = textBox2.Text;
            string thirdColum = textBox3.Text;
            string fourthColum = textBox4.Text;
            string dateColum = dateTimePicker1.Value.ToShortDateString();
            string fifthColum = comboBox2.Text;
            string sixthColum = comboBox3.Text;
            string seventhColumn = comboBox4.Text;
            string eighthColumn = comboBox5.Text;
            string ninethcolumn = textBox5.Text;
            //string tenthcolumn = pictureBox2.Image;
    
            MemoryStream ms = new MemoryStream();
            pictureBox2.Image.Save(ms,pictureBox2.Image.RawFormat);
            byte[] tenthcolumn = ms.ToArray();
    
            table.Rows.Add(firstColum, secondColum, thirdColum, fourthColum, dateColum, fifthColum, sixthColum, seventhColumn, eighthColumn, ninethcolumn, tenthcolumn);