Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have project i which i need to select row data show in web browser tool i do this in mouse click event when user click on cell its shows data
is there any method in data grid view where i show data with select row and also control this with next and previous button
i also done this its work next and previous row but i can get data from data grid view

What I have tried:

mouse click event working well and get the data
C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < dt.Rows.Count && e.RowIndex >= 0)
                webBrowser.DocumentText = dt.Rows[e.RowIndex]["Body"].ToString();
        }

// this is what i want to do but still no getting any data in text box
// in this event how can i apply same thing what i done in mouse click event ? 

private void DataGridView1_CurrentCellChanged(object sender, EventArgs e)
        {
            if (this.dataGridView1.CurrentRow != null)
            {


                textBox2.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();

                this.pre.Enabled = this.dataGridView1.CurrentRow.Index > 0;
                this.next.Enabled = this.dataGridView1.CurrentRow.Index < this.dataGridView1.Rows.Count - 1;
            }
        }

        private void next_Click(object sender, EventArgs e)
        {
            int next = this.dataGridView1.CurrentRow.Index + 1;
            this.dataGridView1.CurrentCell = this.dataGridView1.Rows[next].Cells[this.dataGridView1.CurrentCell.ColumnIndex];
        }

        private void pre_Click(object sender, EventArgs e)
        {
            int prev = this.dataGridView1.CurrentRow.Index - 1;
            this.dataGridView1.CurrentCell = this.dataGridView1.Rows[prev].Cells[this.dataGridView1.CurrentCell.ColumnIndex];
        }
Posted
Updated 24-Apr-16 5:15am
v3

1 solution

Something like this:
C#
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
	string str = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
	MessageBox.Show("You Have Selected " + str);
}

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
	if (this.dataGridView1.Columns[e.ColumnIndex].Name == "MyColumn")
	{
		string MyValue = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
	}
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900