Thursday, January 29, 2015

Datagridview with summary

try this:



Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'put this as your last line in Form_Load
fillTextBoxes()
End Sub

Private Sub DataGridView1_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValidated
fillTextBoxes()
End Sub

Private Sub fillTextBoxes()
'rename textboxes and column names appropriately
txtCity.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("Area").Value IsNot Nothing AndAlso r.Cells("Area").Value.ToString = "city").ToString
txtCountry.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("Area").Value IsNot Nothing AndAlso r.Cells("Area").Value.ToString = "country").ToString
txtOnline.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("Status").Value IsNot Nothing AndAlso r.Cells("Status").Value.ToString = "online").ToString
txtOffline.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("Status").Value IsNot Nothing AndAlso r.Cells("Status").Value.ToString = "offline").ToString
txtTerrace.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("HouseType").Value IsNot Nothing AndAlso r.Cells("HouseType").Value.ToString = "terrace").ToString
txtBungalow.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("HouseType").Value IsNot Nothing AndAlso r.Cells("HouseType").Value.ToString = "bungalow").ToString
txtMale.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("Gender").Value IsNot Nothing AndAlso r.Cells("Gender").Value.ToString = "male").ToString
txtFemale.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("Gender").Value IsNot Nothing AndAlso r.Cells("Gender").Value.ToString = "female").ToString
txtSingle.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("MaritalStatus").Value IsNot Nothing AndAlso r.Cells("MaritalStatus").Value.ToString = "single").ToString
txtMarried.Text = DataGridView1.Rows.Cast(Of DataGridViewRow).Count(Function(r) r.Cells("MaritalStatus").Value IsNot Nothing AndAlso r.Cells("MaritalStatus").Value.ToString = "married").ToString
End Sub

End Class





thanks for any help


No comments:

Post a Comment