Re: Datagridview validation
1) Checking if the TextBox is not blank is easy, just check if the TextBox.TextLength is not 0. Valid information depends on what you define as valid information. Could it only contain certain letters, or maybe numbers only? Only lowercase and so on...
2) There are a few ways of checking if the DataGridView contains information. Firstly, I guess your DGV is bound to a DataTable. First thing to check could be the DataSet.Rows.Count-propery, or the DataGridView.Rows.Count-property to see if it contains any rows at all. If the count is zero, there is no data there.
But, what I would do is this... Since you are going to sort the DGV, you will sort it by a column, right? For that reason, it would be more clever to check if the column actually exists before sorting the DGV. If it doesn't exists, it could be that your DataTable hasn't been populated properly. To check if it exists, you can do:
Code:
If Not DataGridView1.Columns.Contains("ColumnName") Then
MessageBox.Show("Column doesn't exists")
Else
' Do your thing
End If
Does this help you? :)
Re: Datagridview validation
1. To check if there is nothing in the textbox, use:
Code:
Private Sub TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) handles TextBox.Validated
if TextBox.Text = "" then
TextBox.Focus()
end if
End Sub
2. If you have bound the dataset to the datagridview, then:
Code:
tableadapter.Fill(recordset.dataset)
So if there is anything in the dataset, then the Datagridview will be populated. To sort the Datagridview, you could either do that programmatically or just get the user to click on the Column header.
To do it programmatically :
Code:
datagridview.Sort(columnname, System.ComponentModel.ListSortDirection.Ascending)
or
datagridview.Sort(columnname, System.ComponentModel.ListSortDirection.Descending)
I hope this is of use.
Computerman :)