By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

help delegate in c#

fugio
P: 4
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.

Expand|Select|Wrap|Line Numbers
  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.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         Form2 Frm2 = new Form2();
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.             DataGridViewCheckColumn();
  19.  
  20.             Frm2.newEvent += new FrmCheckbox(Frm2_Event);
  21.  
  22.         }
  23.         public void DataGridViewCheckColumn()
  24.         {
  25.  
  26.             dataGridView1.ColumnCount = 6;
  27.  
  28.             dataGridView1.AllowUserToAddRows = false;
  29.  
  30.             DataGridViewCheckBoxColumn colCB = new 
  31.  
  32. DataGridViewCheckBoxColumn();
  33.             colCB.Name = "chkcol";
  34.             colCB.HeaderText = "Select";
  35.             colCB.Width = 40;
  36.             dataGridView1.Columns.Add(colCB);
  37.  
  38.  
  39.             dataGridView1.Columns[0].Name = "C0";
  40.             dataGridView1.Columns[1].Name = "C1";
  41.             dataGridView1.Columns[2].Name = "C2";
  42.             dataGridView1.Columns[3].Name = "C3";
  43.             dataGridView1.Columns[4].Name = "C4";
  44.             dataGridView1.Columns[5].Name = "C5";
  45.  
  46.             dataGridView1.Columns[0].HeaderText = "C0";
  47.             dataGridView1.Columns[1].HeaderText = "C1";
  48.             dataGridView1.Columns[2].HeaderText = "C2";
  49.             dataGridView1.Columns[3].HeaderText = "C3";
  50.             dataGridView1.Columns[4].HeaderText = "C4";
  51.             dataGridView1.Columns[5].HeaderText = "C5";
  52.  
  53.             dataGridView1.Columns[0].Width = 40;
  54.             dataGridView1.Columns[1].Width = 40;
  55.             dataGridView1.Columns[2].Width = 40;
  56.             dataGridView1.Columns[3].Width = 40;
  57.             dataGridView1.Columns[4].Width = 40;
  58.             dataGridView1.Columns[5].Width = 40;
  59.  
  60.  
  61.             dataGridView1.Rows.Add(new string[] { "A1", "B1", "C1", 
  62.  
  63. "D1", "E1", "F1" });
  64.             dataGridView1.Rows.Add(new string[] { "A2", "B2", "C2", 
  65.  
  66. "D2", "E2", "F2" });
  67.             dataGridView1.Rows.Add(new string[] { "A3", "B3", "C3", 
  68.  
  69. "D3", "E3", "F3" });
  70.             dataGridView1.Rows.Add(new string[] { "A4", "B4", "C4", 
  71.  
  72. "D4", "E4", "F4" });
  73.             dataGridView1.Rows.Add(new string[] { "A5", "B5", "C5", 
  74.  
  75. "D5", "E5", "F5" });
  76.             dataGridView1.Rows.Add(new string[] { "A6", "B6", "C6", 
  77.  
  78. "D6", "E6", "F6" });
  79.             dataGridView1.Rows.Add(new string[] { "A7", "B7", "C7", 
  80.  
  81. "D7", "E7", "F7" });
  82.  
  83.  
  84.  
  85.  
  86.             dataGridView1.AutoResizeColumns();
  87.         }
  88.  
  89.         void Frm2_Event()
  90.         {
  91.  
  92.             //for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
  93.             //{
  94.  
  95.             //    if (Convert.ToBoolean(dataGridView1.Rows[i].Cells
  96.  
  97. ["chkcol"].Value) == true )
  98.             //    {
  99.             //        dataGridView1.Rows[i].Cells["chkcol"].Value = false ;
  100.             //    }
  101.  
  102.             //}
  103.             foreach (DataGridViewRow row in dataGridView1.Rows)
  104.             {
  105.                 if (Convert.ToBoolean(row.Cells["chkcol"].Value) == true)
  106.                 {
  107.                     row.Cells["chkcol"].Value = false;
  108.                 }
  109.             }
  110.  
  111.         }
  112.  
  113.         private void dataGridView1_CellContentClick(object sender, 
  114.  
  115. DataGridViewCellEventArgs e)
  116.         {
  117.              for (int i = 0; i <= dataGridView1.RowCount - 1; i++)
  118.             {
  119.                 if (Convert.ToBoolean(dataGridView1.Rows
  120.  
  121. [e.RowIndex].Cells["chkcol"].Value = true))
  122.                 {
  123.                     Frm2.ShowDialog();
  124.                     break;
  125.                 }
  126.             }
  127.  
  128.         }
  129.  
  130.     }
  131. }
Expand|Select|Wrap|Line Numbers
  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.Windows.Forms;
  9.  
  10.  namespace WindowsFormsApplication1
  11.  {
  12.      public delegate void FrmCheckbox();
  13.      public partial class Form2 : Form
  14.      {
  15.          public event FrmCheckbox newEvent;
  16.          public Form2()
  17.          {
  18.              InitializeComponent();
  19.             //button1.Click +=new EventHandler (button1_Click );
  20.          }
  21.  
  22.          private void button1_Click(object sender, EventArgs e)
  23.          {
  24.              if (newEvent != null)
  25.              {
  26.                  newEvent();
  27.  
  28.              }
  29.          }
  30.  
  31.  
  32.  
  33.  
  34.      }
  35.  }
Aug 19 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.