Hi experts,
I am a student working on a project for my company. I work using Microsoft Visual Studio 2005. Language is vb.net. I also work using windows application.
I have a form(EmailContacts) which contains a datagridview and a button to add the data to a textbox of another form. Everything is working fine and i can display data from the database on the datagridview properly. The problem is how do i add a 'Select All' feature such that when the user clicked once on the 'Select All' checkbox, all the checkboxes of the columns are selected?
Pls advise.
These are my codes for the form:-
Public Class EmailContacts
Dim xs As String
Dim conn As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Private Sub EmailContacts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\1B09158\Desktop\aLL.iCONS\database\User.mdb"
'Dim connectionString As String = "Data Source=ITCU-22\SQLEXPRESS;Initial Catalog=User;" & "Integrated Security=SSPI;"
'conn = New SqlConnection(connectionString)
xs = "SELECT CustName,Email,Selection FROM customer"
da = New OleDb.OleDbDataAdapter(xs, conn)
conn.Open()
ds = New DataSet()
'Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
da.Fill(ds, "customer")
DataGridView1.DataSource = ds.Tables("customer")
Email.Show()
End Sub
Private Sub AddContacts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim ds As DataTable = CType(DataGridView1.DataSource, DataTable)
Email.rtbBcc.Text = ""
For i = 0 To (ds.Rows.Count - 1)
If DataGridView1.Rows(i).Cells("Selection").Value IsNot System.DBNull.Value Then
If DataGridView1.Rows(i).Cells("Selection").Value = True Then
Email.rtbBcc.Text += DataGridView1.Rows(i).Cells("Email").Value.ToString()
Email.rtbBcc.Text += ","
'Email.TextBox5.Text += DataGridView1.Rows(i).Cells("CustName").Value.ToString() + "," & vbCrLf
'If DataGridView1.Rows(i).Cells("Selection").Value = True Then
' SendSMS.TextBox1.Text += DataGridView1.Rows(i).Cells("CustName").Value.ToString() + "," & vbCrLf
'End If
End If
End If
Next
Email.rtbBcc.Text = Email.rtbBcc.Text.Remove(Email.rtbBcc.Text.Length - 1, 1)
Me.Hide()
End Sub
End Class