Hi smile,
Once reached to the last recod you have to stop the timer.
Refer below code.
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Speech.Synthesis;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Speech.Synthesis
Code
C#
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Start();
}
private void DisplayData()
{
con = new SqlDbConnect();
con.SqlQuery("select D_Name as 'Doctor',Desk,Service,P_Name as 'Patient',Ticket from tblDoctorCalls where Is_Call='1' and Is_Check='0' order by CallID;");
paging.SelectCommand = con.Cmd;
sBuilder = new SqlCommandBuilder(paging);
ds = new DataSet();
paging.Fill(ds, "tblDoctorCalls");
sTable = ds.Tables["tblDoctorCalls"];
dGVBrand.DataSource = ds.Tables["tblDoctorCalls"].DefaultView;
con.conClose();
DataGridViewColumn column0 = dGVBrand.Columns[0];
column0.Width = 300;
DataGridViewColumn column1 = dGVBrand.Columns[1];
column1.Width = 300;
DataGridViewColumn column2 = dGVBrand.Columns[2];
column2.Width = 150;
DataGridViewColumn column3 = dGVBrand.Columns[3];
column3.Width = 370;
DataGridViewColumn column4 = dGVBrand.Columns[4];
column4.Width = 120;
dGVBrand.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dGVBrand.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dGVBrand.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
dGVBrand.RowsDefaultCellStyle.BackColor = Color.White;
dGVBrand.AlternatingRowsDefaultCellStyle.BackColor = Color.White;
dGVBrand.CellBorderStyle = DataGridViewCellBorderStyle.Single;
dGVBrand.DefaultCellStyle.SelectionBackColor = Color.SteelBlue;
dGVBrand.DefaultCellStyle.SelectionForeColor = Color.White;
dGVBrand.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dGVBrand.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dGVBrand.AllowUserToResizeColumns = true;
dGVBrand.AllowUserToAddRows = true;
}
static int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
try
{
this.DisplayData();
if (dGVBrand.Rows.Count - 1 == i)
{
i = 0;
}
if (dGVBrand.Rows[i].Cells[1].Value != null)
{
SpeechSynthesizer speechSynthesizerObj = new SpeechSynthesizer();
string message = "Doctor" + dGVBrand.Rows[i].Cells[0].Value + " ";
message += "Desk" + dGVBrand.Rows[i].Cells[1].Value + " ";
message += "Service" + dGVBrand.Rows[i].Cells[2].Value + " ";
message += "Mister " + dGVBrand.Rows[i].Cells[3].Value;
message += "and Ticket No " + dGVBrand.Rows[i].Cells[4].Value;
speechSynthesizerObj.SpeakAsync(message);
for (int j = 0; j < dGVBrand.Rows.Count - 1; j++)
{
dGVBrand.Rows[j].Selected = i == j ? true : false;
}
i++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
VB.Net
Partial Public Class Form1
Public Sub New()
InitializeComponent()
timer1.Start()
End Sub
Private Sub DisplayData()
con = New SqlDbConnect()
con.SqlQuery("select D_Name as 'Doctor',Desk,Service,P_Name as 'Patient',Ticket from tblDoctorCalls where Is_Call='1' and Is_Check='0' order by CallID;")
paging.SelectCommand = con.Cmd
sBuilder = New SqlCommandBuilder(paging)
ds = New DataSet()
paging.Fill(ds, "tblDoctorCalls")
sTable = ds.Tables("tblDoctorCalls")
dGVBrand.DataSource = ds.Tables("tblDoctorCalls").DefaultView
con.conClose()
Dim column0 As DataGridViewColumn = dGVBrand.Columns(0)
column0.Width = 300
Dim column1 As DataGridViewColumn = dGVBrand.Columns(1)
column1.Width = 300
Dim column2 As DataGridViewColumn = dGVBrand.Columns(2)
column2.Width = 150
Dim column3 As DataGridViewColumn = dGVBrand.Columns(3)
column3.Width = 370
Dim column4 As DataGridViewColumn = dGVBrand.Columns(4)
column4.Width = 120
dGVBrand.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dGVBrand.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
dGVBrand.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
dGVBrand.RowsDefaultCellStyle.BackColor = Color.White
dGVBrand.AlternatingRowsDefaultCellStyle.BackColor = Color.White
dGVBrand.CellBorderStyle = DataGridViewCellBorderStyle.Single
dGVBrand.DefaultCellStyle.SelectionBackColor = Color.SteelBlue
dGVBrand.DefaultCellStyle.SelectionForeColor = Color.White
dGVBrand.DefaultCellStyle.WrapMode = DataGridViewTriState.[True]
dGVBrand.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dGVBrand.AllowUserToResizeColumns = True
dGVBrand.AllowUserToAddRows = True
End Sub
Shared i As Integer = 0
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
Try
Me.DisplayData()
If dGVBrand.Rows.Count - 1 = i Then
i = 0
End If
If dGVBrand.Rows(i).Cells(1).Value IsNot Nothing Then
Dim speechSynthesizerObj As SpeechSynthesizer = New SpeechSynthesizer()
Dim message As String = "Doctor" & dGVBrand.Rows(i).Cells(0).Value & " "
message += "Desk" & dGVBrand.Rows(i).Cells(1).Value & " "
message += "Service" & dGVBrand.Rows(i).Cells(2).Value & " "
message += "Mister " & dGVBrand.Rows(i).Cells(3).Value
message += "and Ticket No " & dGVBrand.Rows(i).Cells(4).Value
speechSynthesizerObj.SpeakAsync(message)
For j As Integer = 0 To dGVBrand.Rows.Count - 1 Step 1
dGVBrand.Rows(j).Selected = If(i = j, True, False)
Next
i += 1
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
End Class
Screenshot