Hey satabeach,
Please refer below sample.
Namespaces
using System.Data;
VB.Net
Imports System.Data
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
this.BindDataGridView();
}
private void BindDataGridView()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ContactNumber", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Messaage",typeof(string)) });
dt.Rows.Add(123456, "John Hammond", "Hey");
dt.Rows.Add(235489, "Mudassar Khan", "Hello");
dt.Rows.Add(345556, "Suzanne Mathews", "Hmmmm");
dt.Rows.Add(466677, "Robert Schidner", "Whats'up");
this.dataGridView1.DataSource = dt;
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);
}
private void Send(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
bool isSelected = Convert.ToBoolean(row.Cells["checkBoxColumn"].Value);
if (isSelected)
{
string contactNumber = row.Cells[1].Value.ToString();
string message = row.Cells[3].Value.ToString();
if (!SendSMS(message, contactNumber))
{
MessageBox.Show("Problem occured while sending SMS", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}
private bool SendSMS(string message, string number)
{
//Send SMS Code that return the status.
bool status = false;
return status;
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.BindDataGridView()
End Sub
Private Sub BindDataGridView()
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("ContactNumber", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Messaage", GetType(String))})
dt.Rows.Add(123456, "John Hammond", "Hey")
dt.Rows.Add(235489, "Mudassar Khan", "Hello")
dt.Rows.Add(345556, "Suzanne Mathews", "Hmmmm")
dt.Rows.Add(466677, "Robert Schidner", "Whats'up")
Me.dataGridView1.DataSource = dt
Dim checkBoxColumn As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn()
checkBoxColumn.HeaderText = ""
checkBoxColumn.Width = 30
checkBoxColumn.Name = "checkBoxColumn"
dataGridView1.Columns.Insert(0, checkBoxColumn)
End Sub
Private Sub Send(ByVal sender As Object, ByVal e As EventArgs) Handles btnTransfer.Click
For Each row As DataGridViewRow In dataGridView1.Rows
Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("checkBoxColumn").Value)
If isSelected Then
Dim contactNumber As String = row.Cells(1).Value.ToString()
Dim message As String = row.Cells(3).Value.ToString()
If Not SendSMS(message, contactNumber) Then
MessageBox.Show("Problem occured while sending SMS", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
Next
End Sub
Private Function SendSMS(ByVal message As String, ByVal number As String) As Boolean
'Send SMS Code that return the status.
Dim status As Boolean = False
Return status
End Function