DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("index", typeof(Int32));
dt.Columns.Add("name", typeof(String));
dt.Columns.Add("changed", typeof(Int32));
dt.Rows.Add(new object[] { 1, "Chris" ,0});
dt.Rows.Add(new object[] { 2, "Angie", 0 });
dt.Rows.Add(new object[] { 3, "Tim", 0 });
dt.Rows.Add(new object[] { 4, "Angela", 0 });
dt.Rows.Add(new object[] { 5, "Bob", 0 });
dt.Rows.Add(new object[] { 6, "Lory", 0 });
dt.Rows.Add(new object[] { 7, "Michael", 0 });
dt.Rows.Add(new object[] { 8, "Steve", 0 });
dt.Rows.Add(new object[] { 9, "Nicky", 0 });
dt.Rows.Add(new object[] { 10, "Dave", 0 });
dt.DefaultView.Sort = "index DESC,name";
//BindingSource bindSource = new BindingSource();
//bindSource.DataSource = dt;
dataGridView1.DataSource = dt;
}
private void button1_Click(object sender, EventArgs e)
{
foreach (DataRow dr in dt.Rows)
{
if (dr["changed"].ToString() == "1")
{
MessageBox.Show(dr["name"].ToString());
}
}
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
if (((DataRowView)row.DataBoundItem).Row.RowState != DataRowState.Unchanged)
{
//row.HeaderCell.Value = "***";
row.Cells[2].Value = 1;
}
}
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
dataGridView1.Columns[2].Visible = false;
}