0
Answer

datagrid dynamic column (image) deletion problem inwindow application

shashikant singh

shashikant singh

12y
1.3k
1
I have a datagridview whose value are coming from xml. I have one column to store image.when i delete last row then data is deleted from xml.but is not deleted from datagridview. Below i pasting  the code



 protected void Bindlayoutdata()
        {
            try
            {
                string path = Readxml();
                if (path != "")
                {
                    if (File.Exists(path + "\\oohmp\\xml\\layout.xml"))
                    {
                        DataSet ds = new DataSet();
                        ds.ReadXml(path + "\\oohmp\\xml\\layout.xml");
                        dataGrid_layoutdetail.DataSource = ds.Tables[0].DefaultView;
                        for (int i = 0; i < dataGrid_layoutdetail.Rows.Count; i++)
                        {
                            string[] thumbname = (dataGrid_layoutdetail.Rows[i].Cells["imagepreviewpath"].Value.ToString()).Split('\\');
                            if (File.Exists(path + "\\oohmp\\layouts\\" + thumbname[1]))
                            {
                                Image img = Image.FromFile(path + "\\oohmp\\layouts\\" + thumbname[1]);
                                img = img.GetThumbnailImage(100, 100, null, IntPtr.Zero);
                                dataGrid_layoutdetail.Rows[i].Cells["layoutpreview"].Value = img;
                            }
                            else
                            {
                                Image img = Image.FromFile(getpath() + "\\ffmpeg\\" + "Preview.png");
                                img = img.GetThumbnailImage(100, 100, null, IntPtr.Zero);
                                dataGrid_layoutdetail.Rows[i].Cells["layoutpreview"].Value = img;

                            }
                            dataGrid_layoutdetail.Rows[i].Cells["layoutid"].Value = (i + 1);
                        }
                    }
                    else
                    {
                        //group_imginfo.Visible = true;
                        //dataGridView2.Visible = false;

                        dataGrid_layoutdetail.ClearSelection();
                        //dataGrid_layoutdetail.Dispose();
                        dataGrid_layoutdetail.Visible = true;
                        //lbl_img_info.Visible = true;
                        //txt_imagename.Text = "";
                        //System.Threading.Thread.Sleep(3000);
                        //MessageBox.Show("All Images deleted.");

                        //DataTable dt = new DataTable();
                        //dt.Columns.Add("image");
                        //DataRow dr = dt.NewRow();
                        //dr["image"] = "";
                        //dt.Rows.Add(dr);
                        //dataGridView2.DataSource = dt.DefaultView;
                        //dataGridView2.DataSource = null;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Occured", "Message");
            }
        }