I new to programming and need help with selecting dataGridView and checking first column. When I click on "checkBox1" (select all) want to select all cells (rows) and to check all checkBox in dataGrid in columns "No", for now code just select rows without checking them.
input file looks something like:
900006724 00000090000698511 SAVSKI IVАN SREMSKA 101
900007054 000000ZU900006931 SAVSKI JOVАNOVIĆ 29.NOVEMBRA 504
900009856 000000Ih900009856 NOVI IVАN 29.NOVEMBRA 403
and code:
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.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnload_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
textBox1.Text = of.FileName;
dataGridView1.DataSource = Class1.LoadUserListFromFile(textBox1.Text);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
dataGridView1.SelectAll();
checkBox2.Checked = false;
checkBox1.Checked = !checkBox2.Checked;
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
dataGridView1.ClearSelection();
checkBox1.Checked = false;
checkBox2.Checked=!checkBox1.Checked;
}
public class Class1
{
public bool No { get; set; }
public string Id { get; set; }
public string Sity { get; set; }
public string Surname { get; set; }
public string Name { get; set; }
public string Street { get; set; }
public string PostalNo { get; set; }
public string Sity1 { get; set; }
public string Date { get; set; }
public string CardDate { get; set; }
public string PU { get; set; }
public string Password { get; set; }
public string IdentificationNo { get; set; }
public static List<Class1> LoadUserListFromFile(string path)
{
var users = new List<Class1>();
foreach (var line in File.ReadAllLines(path))
{
var columns = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
users.Add(new Class1
{
No = false,
Id = line.Substring(22, 12).Trim(),
Sity = line.Substring(48, 20).Trim(),
Surname = line.Substring(81, 32).Trim(),
Name = line.Substring(113, 36).Trim(),
Street = line.Substring(177, 24).Trim(),
PostalNo = line.Substring(241, 9).Trim(),
Sity1 = line.Substring(263, 20).Trim(),
Date = line.Substring(343, 12).Trim(),
CardDate = line.Substring(570, 17).Trim(),
PU = line.Substring(614, 25).Trim(),
Password = line.Substring(694, 10).Trim(),
IdentificationNo = line.Substring(710, 13).Trim(),
});
}
return users;
}
public static string input { get; set; }
public static string[] delimiters { get; set; }
}
}
}