Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This is a simple question, i am using a if selection to determine if a row isnt selected in a grid view then to show a message telling the user to select a gridview row.

I have the follow psuedo code for it but need help translating it into C#

If(GridView1.SelectedRow == 0)
{
MessageBox.Show(Select A Row First)
}

Please help me converting this to C#, P.S Already lloked online for help for this and couldnt find anything that worked.
Posted

You were just missing the count, which counts the amount of selected rows.

I've replaced SelectedRow with SelectedRows and added the .count which will return the number of selected rows.

Hope this helps.

C#
If(GridView1.SelectedRows.Count == 0)
 {
 MessageBox.Show(Select A Row First)
 }
 
Share this answer
 
v2
Int32 selectedrowcount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);


if (selectedrowcount > 0)
{
row selected!
}

else

{
plz Select the row!
}


use this and give me bless ha ha ha!
 
Share this answer
 
v2

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