Vishal anand

Vishal anand

  • NA
  • 3
  • 1.9k

how make horizontal scrollbar move in c# windows form

Dec 28 2013 4:08 AM
respected Sir 
 
my name is vishal. i am having trouble in code of horizontal scroll bar in c# windows forms. what i want is when user clicks or scroll using horizontal scroll bar he should see the datas entered in form before. Any help would be appreciated.
 
my form name: Technician
 
Technician form code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace DRRS_in_Csharp
{
public partial class Technician : Form
{
long pUserID;
public Technician()
{
InitializeComponent();
}

private void Technician_Load(object sender, EventArgs e)
{
dtDOB.MaxDate = dtDOB.Value;
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan16;Integrated Security=true");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
DataTable dt = new DataTable();
string s1 = ("Select td.technician_first_name,td.technican_middle_name,td.technician_last_name,t.technician_dob,t.technician_sex,td.technician_type from TECHNICIANDETAIL td,TECHNICIAN t where td.technician_id=t.technician_id");
cmd = new SqlCommand(s1, conn);
if (dt.Rows.Count == -1)
{
scrRec.Visible = true;
long i = 0;
do
{
i = (i + 1);
} while (dt.Rows.Count == -1);
scrRec.Maximum = Convert.ToInt32(i - 1);
lblRecPos.Text = "Record Pos(1/" + i + ")";
txtFname.Enabled = false;
txtMname.Enabled = false;
txtLname.Enabled = false;
dtDOB.Enabled = false;
cboSex.Enabled = false;
txtFname.Text = cmd.Parameters.AddWithValue("technician_first_name", SqlDbType.VarChar).Value.ToString();
txtMname.Text = cmd.Parameters.AddWithValue("technician_middle_name", SqlDbType.VarChar).Value.ToString();
txtLname.Text = cmd.Parameters.AddWithValue("technician_last_name", SqlDbType.VarChar).Value.ToString();
dtDOB.Value = Convert.ToDateTime(cmd.Parameters.AddWithValue("technician_dob", SqlDbType.Date).Value);
if ((cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value is DBNull) && (Convert.ToBoolean(cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value == false.GetType())))
{
cmd.Parameters.AddWithValue("technician_type", cboTechType.SelectedIndex);
}
else
{
cboTechType.SelectedIndex = 0;
}
if (cmd.Parameters.AddWithValue("technician_sex", SqlDbType.VarChar).Value == "M")
{
cboSex.SelectedIndex = 0;
}
else
{
cboSex.SelectedIndex = 1;
}
}
else
{
scrRec.Visible = true;
button1.Text = "Create";
}
conn.Close();
}

private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "New")
{
txtFname.Enabled = true;
txtMname.Enabled = true;
txtLname.Enabled = true;
cboSex.Enabled = true;
dtDOB.Enabled = true;

txtFname.Text = "";
txtMname.Text = "";
txtLname.Text = "";
cboSex.SelectedIndex = -1;
txtFname.Focus();
button1.Text = "Create";
}
string dFieldName = "";
Boolean vEmptyB = false;
if (txtFname.Text.ToString().Trim() == "")
{
vEmptyB = true;
dFieldName = "Please enter the technician first name";
}
else if (cboSex.SelectedIndex == -1)
{
vEmptyB = true;
dFieldName = "Please select gender for technician";
}
else if (cboTechType.SelectedIndex == -1)
{
vEmptyB = true;
dFieldName = "Please select technician type";
}
if (vEmptyB==true)
{
MessageBox.Show(dFieldName + "should not be empty");
return;
}
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan16;Integrated Security=true");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd = new SqlCommand("insert into TECHNICIAN(technician_dob,technician_sex,row_upd_date,user_id)" + "Values(@technician_dob,@technician_sex,GetDate(),@user_id)", conn);
if (cboSex.SelectedIndex == 0)
{
cmd.Parameters.AddWithValue("@technician_sex", SqlDbType.VarChar).Value = "M";
}
else
{
cmd.Parameters.AddWithValue("@technician_sex", SqlDbType.VarChar).Value = "F";
}
cmd.Parameters.AddWithValue("@technician_dob", dtDOB.Value);
cmd.Parameters.AddWithValue("@user_id", pUserID);
cmd.ExecuteNonQuery();

cmd = new SqlCommand("Insert into TECHNICIANDETAIL(technician_first_name,technician_middle_name,technician_last_name,row_upd_date,status,user_id,technician_type)" + "Values(@technician_first_name,@technician_middle_name,@technician_last_name,GetDate(),@status,@user_id,@technician_type)", conn);
cmd.Parameters.AddWithValue("@technician_first_name", txtFname.Text);
cmd.Parameters.AddWithValue("@technician_middle_name", txtMname.Text);
cmd.Parameters.AddWithValue("@technician_last_name", txtLname.Text);
cmd.Parameters.AddWithValue("@technician_type", cboTechType.SelectedIndex);
cmd.Parameters.AddWithValue("@status", true);
cmd.Parameters.AddWithValue("@user_id", pUserID);
cmd.ExecuteNonQuery();
((MDIParent5)this.MdiParent).updateUserActivities(pUserID, 3, txtFname.Text + "technician detail was added successfully");
MessageBox.Show("Technician detail was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
conn.Close();


}

my horizontal scroll bar name: scrRec
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan16;Integrated Security=true");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
lblRecPos.Text = "Record Pos(" + scrRec.Value + 1 + "/" + scrRec.Maximum + 1 + ")";
if (dt.Rows.Count == -1)
{
txtFname.Enabled = false;
txtMname.Enabled = false;
txtLname.Enabled = false;
dtDOB.Enabled = false;
cboSex.Enabled = false;
txtFname.Text = cmd.Parameters.AddWithValue("technician_first_name", SqlDbType.VarChar).Value.ToString();
txtMname.Text = cmd.Parameters.AddWithValue("technician_middle_name", SqlDbType.VarChar).Value.ToString();
txtLname.Text = cmd.Parameters.AddWithValue("technician_last_name", SqlDbType.VarChar).Value.ToString();
dtDOB.Value = Convert.ToDateTime(cmd.Parameters.AddWithValue("technician_dob", SqlDbType.Date).Value);
if ((cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value is DBNull) && (Convert.ToBoolean(cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value == false.GetType())))
{
cmd.Parameters.AddWithValue("technician_type", cboTechType.SelectedIndex);
}
else
{
cboTechType.SelectedIndex = 0;
}
if (cmd.Parameters.AddWithValue("technician_sex", SqlDbType.VarChar).Value == "M")
{
cboSex.SelectedIndex = 0;
}
else
{
cboSex.SelectedIndex = 1;
}
conn.Close();
}
 
 
 
 

Answers (1)