0

I'm working on a Windows Form that's got two DataGrids.

I'm currently trying to make it so that when one cell is selected in DataGridView1, something else is being displayed in DataGridView2.

The problem is that when I run my app, selecting any of the cells doesn't do anything at all.

I've tried using

private void DataGridView1_SelectionChanged(object sender, EventArgs e)
{
MessageBox.Show("The selected cell has changed!");
};

to check and see if the event is registering, and nothing happened.

The SelectionMode for the DataGridView is set to CellSelect.

What am I doing wrong?

Thanks In Advance.

Hitesh Anshani
  • 1,499
  • 9
  • 19
Miclaush
  • 1
  • 1

1 Answers1

0

Examples:-Check This Also

     private void datagridview1_SelectionChanged(object sender, EventArgs e)
     {
         if (datagridview1.SelectedCells.Count > 0)
         {
             int selectedrowindex = datagridview1.SelectedCells[0].RowIndex;

             DataGridViewRow selectedRow = datagridview1.Rows[selectedrowindex];  

              string a = Convert.ToString(selectedRow.Cells["you have to mention you cell  corresponding column name"].Value);           


         }
     }

Use this And Take reference

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
        {
           MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
        }
    }

Another

MessageBox.Show(dataGridView1.SelectedCells[0].Value.ToString());

Check this property Also DataGridView1.FullRowSelect = true

Hitesh Anshani
  • 1,499
  • 9
  • 19
  • I tried both of these and switching it to FullRowSelect and it still won't register me clicking or selecting any of the cells or rows despite them being highlighted as selected :( – Miclaush Jun 29 '18 at 15:08
  • Then Add Full Code Please – Hitesh Anshani Jun 29 '18 at 15:11
  • If you want whole new then refer this tutorial https://www.c-sharpcorner.com/UploadFile/1e050f/edit-and-update-record-in-gridview-in-Asp-Net/ – Hitesh Anshani Jun 29 '18 at 15:13
  • Another tutorial https://www.c-sharpcorner.com/UploadFile/1e050f/insert-update-and-delete-record-in-datagridview-C-Sharp/ – Hitesh Anshani Jun 29 '18 at 15:16
  • private void grdAdreseClienti_SelectionChanged(object sender, EventArgs e) { MessageBox.Show("It works!");} this is the exact code I'm using, minus the formatting. Selecting a cell does not do anything at all :( – Miclaush Jun 29 '18 at 15:28