I'm implementing a function. While choosing any of datagridviewcheckboxcolumn in form1 and show form2 when click button to close, datagridviewcheckboxcolumn in the form1 will is false ?
Please help on this.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Form2 Frm2 = new Form2();
public Form1()
{
InitializeComponent();
DataGridViewCheckColumn();
Frm2.newEvent += new FrmCheckbox(Frm2_Event);
}
public void DataGridViewCheckColumn()
{
dataGridView1.ColumnCount = 6;
dataGridView1.AllowUserToAddRows = false;
DataGridViewCheckBoxColumn colCB = new
DataGridViewCheckBoxColumn();
colCB.Name = "chkcol";
colCB.HeaderText = "Select";
colCB.Width = 40;
dataGridView1.Columns.Add(colCB);
dataGridView1.Columns[0].Name = "C0";
dataGridView1.Columns[1].Name = "C1";
dataGridView1.Columns[2].Name = "C2";
dataGridView1.Columns[3].Name = "C3";
dataGridView1.Columns[4].Name = "C4";
dataGridView1.Columns[5].Name = "C5";
dataGridView1.Columns[0].HeaderText = "C0";
dataGridView1.Columns[1].HeaderText = "C1";
dataGridView1.Columns[2].HeaderText = "C2";
dataGridView1.Columns[3].HeaderText = "C3";
dataGridView1.Columns[4].HeaderText = "C4";
dataGridView1.Columns[5].HeaderText = "C5";
dataGridView1.Columns[0].Width = 40;
dataGridView1.Columns[1].Width = 40;
dataGridView1.Columns[2].Width = 40;
dataGridView1.Columns[3].Width = 40;
dataGridView1.Columns[4].Width = 40;
dataGridView1.Columns[5].Width = 40;
dataGridView1.Rows.Add(new string[] { "A1", "B1", "C1",
"D1", "E1", "F1" });
dataGridView1.Rows.Add(new string[] { "A2", "B2", "C2",
"D2", "E2", "F2" });
dataGridView1.Rows.Add(new string[] { "A3", "B3", "C3",
"D3", "E3", "F3" });
dataGridView1.Rows.Add(new string[] { "A4", "B4", "C4",
"D4", "E4", "F4" });
dataGridView1.Rows.Add(new string[] { "A5", "B5", "C5",
"D5", "E5", "F5" });
dataGridView1.Rows.Add(new string[] { "A6", "B6", "C6",
"D6", "E6", "F6" });
dataGridView1.Rows.Add(new string[] { "A7", "B7", "C7",
"D7", "E7", "F7" });
dataGridView1.AutoResizeColumns();
}
void Frm2_Event()
{
//for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
//{
// if (Convert.ToBoolean(dataGridView1.Rows[i].Cells
["chkcol"].Value) == true )
// {
// dataGridView1.Rows[i].Cells["chkcol"].Value = false ;
// }
//}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (Convert.ToBoolean(row.Cells["chkcol"].Value) == true)
{
row.Cells["chkcol"].Value = false;
}
}
}
private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
for (int i = 0; i <= dataGridView1.RowCount - 1; i++)
{
if (Convert.ToBoolean(dataGridView1.Rows
[e.RowIndex].Cells["chkcol"].Value = true))
{
Frm2.ShowDialog();
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public delegate void FrmCheckbox();
public partial class Form2 : Form
{
public event FrmCheckbox newEvent;
public Form2()
{
InitializeComponent();
//button1.Click +=new EventHandler (button1_Click );
}
private void button1_Click(object sender, EventArgs e)
{
if (newEvent != null)
{
newEvent();
}
}
}
}