Click here to Skip to main content
14,159,205 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
If datagrid no have rows in my textbox have values from last selected values...

Need help IF DATAGRID NO HAVE VALUES TEXTBOX EMPTY

Thank you

What I have tried:

 private void testDataGridView_SelectionChanged(object sender, EventArgs e)
        {

            if (testDataGridView.SelectedRows.Count > 0) 
            {

            string test = testDataGridView.SelectedRows[0].Cells["columnname"].Value.ToString();

testTextBox.Text = test;

             }
         }
Posted
Updated 24-Mar-19 5:58am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

string test = string.Empty;

if (testDataGridView.SelectedRows.Count > 0) {
    test = testDataGridView.SelectedRows[0].Cells["columnname"].Value.ToString();
}

testTextBox.Text = test;
   
Comments
Goran Bibic 24-Mar-19 12:21pm
   
Thank you

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190518.1 | Last Updated 24 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100