C# - Winform

Hi See below my code
  private void dataGridViewFranceCube_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                DataGridViewRow rowNumber = dataGridViewFranceCube.SelectedRows[0];
                txtitem.Text = rowNumber.Cells[0].Value.ToString();
                txtProductDescription.Text = rowNumber.Cells[2].Value.ToString();
            }

Open in new window


Sometime this is not working, any idea where im doing mistake, What i need is ,when user click i need to get row data for example
if user click on row 2 i need column1 and column 2 data.
LVL 10
ukerandiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naitik GamitSoftware DeveloperCommented:
Try CellClick event instead of CellContentClick event.

The CellContentClick event won't necessarily fire when you click in the cell, the user has to click into the content area of the cell, like the text.

private void dataGridViewFranceCube_CellClick(object sender, DataGridViewCellEventArgs e)
  {
               DataGridView ObjGrid = sender as DataGridView;
               if(ObjGrid != null)
                 {
                         DataGridViewCell selectedCell = ObjGrid .SelectedCells[0];
                 }

   }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ukerandiAuthor Commented:
private void dataGridViewFranceCube_CellClick(object sender,  DataGridViewCellEventArgs e)
            {
                MessageBox.Show("Test");

           

                DataGridViewImageCell cell = (DataGridViewImageCell)
                    dataGridViewFranceCube.Rows[e.RowIndex].Cells[e.ColumnIndex];

               

             
            }


and also i have add following code to Designer.cs also but still not working

   this.dataGridViewFranceCube_CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewFranceCube_CellClick);
0
Franck GaspozSoftware Architect, Technical ExpertCommented:
Hi,
do you have any exception thrown ? if yes can you show it ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.