This will do it:
private void DataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
txtSumClient.Text = DataGridView1.Rows.Count.ToString();
txtSumClient.ForeColor = Color.Red
}
Specifically you should not use a Timer.
I'm a little concerned about your comment
Quote:
The issue is I have to select the datagridview data before it count to the textbox what I need is when the form load the count (Number of Clients) is the textbox
You cannot select any data in the datagridview until the form is loaded. So note that the code I've given you so far will count all of the rows in the datagrid. It will always be one row out unless you have disabled the user's ability to add new rows e.g. (I have a function
ReadData
that returns a DataTable)
private void Form1_Load(object sender, EventArgs e)
{
DataGridView1.AllowUserToAddRows = false;
DataGridView1.DataSource = ReadData();
}
If you want a textbox to show the number of
selected rows then the event you need to hook up is the SelectionChanged event e.g.
private void DataGridView1_SelectionChanged(object sender, EventArgs e)
{
txtSelected.Text = DataGridView1.SelectedRows.Count.ToString();
}
Assuming you have
DataGridView1.MultiSelect = true;
(either in code or in the Properties window)