Click here to Skip to main content
15,889,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a datagridview with a few rows. I want to refrain user from clicking the white spaces (empty area after rows)

Or at least I could catch when user clicks the empty area, so a message could be displayed.

Please advise how to do it.

Thanks
Posted

1 solution

If you are talking about the empty area inside the grid after rows then set AutoSizeColumnsMode property of grid to FILL. then columns will be auto sized to gridview width.

If you are talking about an empty cell then -
VB
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    Dim MyVal As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString
    If String.IsNullOrWhiteSpace(MyVal) Then
        MsgBox("You click on empty cell")
    End If
End Sub
 
Share this answer
 

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