Lerroy Fernandes

Lerroy Fernandes

  • NA
  • 17
  • 10.3k

How to handle these errors?

Feb 2 2021 3:22 PM
This is my code
 
I need help to handle a few errors that i dont know why im seeing
 
1. Automatically a new grid for Image is created. 
2. An error keeps popping up 
 
 

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.IO;  
  11. namespace Amal_Inventory  
  12. {  
  13. public partial class Form1 : Form  
  14. {  
  15. public Form1()  
  16. {  
  17. InitializeComponent();  
  18. }  
  19. private void label1_Click(object sender, EventArgs e)  
  20. {  
  21. }  
  22. private void button3_Click(object sender, EventArgs e)  
  23. {  
  24. }  
  25. private void button4_Click(object sender, EventArgs e)  
  26. {  
  27. }  
  28. private void button6_Click(object sender, EventArgs e)  
  29. {  
  30. }  
  31. private void button5_Click(object sender, EventArgs e)  
  32. {  
  33. if (MessageBox.Show("Sure ??""Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)==DialogResult.OK)  
  34. {  
  35. if (this.dataGridView1.SelectedRows.Count > 0)  
  36. {  
  37. dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);  
  38. }  
  39. textBox1.Text = "";  
  40. textBox2.Text = "";  
  41. textBox3.Text = "";  
  42. textBox4.Text = "";  
  43. textBox5.Text = "";  
  44. textBox6.Text = "";  
  45. textBox7.Text = "";  
  46. textBox8.Text = "";  
  47. textBox9.Text = "";  
  48. }  
  49. }  
  50. private void button7_Click(object sender, EventArgs e)  
  51. {  
  52. textBox1.Text = "";  
  53. textBox2.Text = "";  
  54. textBox3.Text = "";  
  55. textBox4.Text = "";  
  56. textBox5.Text = "";  
  57. textBox6.Text = "";  
  58. textBox7.Text = "";  
  59. textBox8.Text = "";  
  60. textBox9.Text = "";  
  61. pictureBox1.Image = "";  
  62. }  
  63. private void button8_Click(object sender, EventArgs e)  
  64. {  
  65. Update();  
  66. }  
  67. private void button2_Click(object sender, EventArgs e)  
  68. {  
  69. int n = dataGridView1.Rows.Add();  
  70. dataGridView1.Rows[n].Cells[0].Value = textBox1.Text;  
  71. dataGridView1.Rows[n].Cells[1].Value = textBox2.Text;  
  72. dataGridView1.Rows[n].Cells[2].Value = textBox3.Text;  
  73. dataGridView1.Rows[n].Cells[3].Value = textBox4.Text;  
  74. dataGridView1.Rows[n].Cells[4].Value = textBox5.Text;  
  75. dataGridView1.Rows[n].Cells[5].Value = textBox6.Text;  
  76. dataGridView1.Rows[n].Cells[6].Value = textBox7.Text;  
  77. dataGridView1.Rows[n].Cells[7].Value = textBox8.Text;  
  78. dataGridView1.Rows[n].Cells[8].Value = textBox9.Text;  
  79. MemoryStream mmst = new MemoryStream();  
  80. pictureBox1.Image.Save(mmst, pictureBox1.Image.RawFormat);  
  81. byte[] img = mmst.ToArray();  
  82. dataGridView1.Rows.Add(img);  
  83. }  
  84. private void Form1_Load(object sender, EventArgs e)  
  85. {  
  86. DataGridViewImageColumn dvgimage = new DataGridViewImageColumn();  
  87. dvgimage.HeaderText = "Image";  
  88. dvgimage.ImageLayout = DataGridViewImageCellLayout.Stretch;  
  89. dataGridView1.Columns.Add(dvgimage);  
  90. dataGridView1.RowTemplate.Height = 120;  
  91. dataGridView1.AllowUserToAddRows = false;  
  92. }  
  93. private void Form1_FormClosing(object sender, FormClosingEventArgs e)  
  94. {  
  95. DialogResult confirm = MessageBox.Show("Are you sure?""Exit", MessageBoxButtons.YesNo);  
  96. }  
  97. private void button1_Click(object sender, EventArgs e)  
  98. {  
  99. OpenFileDialog openfiledialogue1 = new OpenFileDialog();  
  100. openfiledialogue1.Filter = "Choose Image (*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif";  
  101. if (openfiledialogue1.ShowDialog() == DialogResult.OK)  
  102. {  
  103. pictureBox1.Image = new Bitmap(openfiledialogue1.FileName);  
  104. }  
  105. }  
  106. }  
  107. }  
 

Answers (4)