Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 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

string test = string.Empty;

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

testTextBox.Text = test;
 
Share this answer
 
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)



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