IFAR AKR

IFAR AKR

  • NA
  • 17
  • 2.1k

Datagridview Checkbox last row click mean

Feb 14 2017 10:36 AM
Pls everyone help me....
if i click the datagridview checkbox columns 1 to 4 rows, but 1,2,3 rows only false 4th row wasn't false...??? for eg: 1 to 5 rows means 5th rows wasn't false....  why..?? If you provide more details we can provide better help....
 Coding and project file have been mentioned below.......
 
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;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.IO;
using System.Drawing.Imaging;

namespace Checkbox
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=RAFIUDDEEN-PC\\SQLEXPRESS;Initial Catalog=KH_Asset;Integrated Security=True");
public Form1()
{
InitializeComponent();
}

private void bindingNavigator1_RefreshItems(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
assetgroup();
}

private void assetgroup()
{
dataGridView14.ClearSelection();
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlDataAdapter adapt = new SqlDataAdapter();
adapt = new SqlDataAdapter("select Asset_Code,Description,Types,Part,Manufacturer,Vendor,Invoice_No,Purchased_Date,Warrenty_End_Date from Asset_KH_Detail ", con);
adapt.Fill(dt); dataGridView14.DataSource = dt;
{
int i = 1; foreach (DataGridViewRow row in dataGridView14.Rows)
{
row.Cells[1].Value = i;
i++;
}
}
dataGridView14.AllowUserToAddRows = false; dataGridView14.AllowUserToDeleteRows = false;
dataGridView14.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold);
dataGridView14.DefaultCellStyle.Font = new System.Drawing.Font("Times New Roman", 8.75F, System.Drawing.FontStyle.Regular);
}

/*Delete button*/ private void toolStripButton11_Click(object sender, EventArgs e)
{
try
{
int i = 0;
foreach (DataGridViewRow item in dataGridView14.Rows)
{
if (item.Cells[0].Value != null)

if (bool.Parse(item.Cells[0].Value.ToString()))
{
item.Cells[0].Value = false;
MessageBox.Show("Selected Rows : " + item.Cells[0].RowIndex.ToString() + " and serial No is" + item.Cells[1].Value.ToString());
}
}
}
catch (SystemException ex)
{
MessageBox.Show(ex.Message);
}
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow row in this.dataGridView14.Rows)
{
row.Cells[0].Value = row.Cells[0].Value == null ? true : !(bool)row.Cells[0].Value;
}
}

}
}

Attachment: Checkbox.rar

Answers (3)