473,750 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

horizontal scroll bar in c# windows forms with sql server 2008

7 New Member
Hi my name is vishal. I am converting my vb6 project(vb6,ado db with ms access) to c# with sql server 2008. I have a horizontal scroll bar in a form with some fields(labels,t extboxes,combob ox and datetime picker) such as first name, last name,sex,dob. what i expect from horizontal scroll bar is that when i scroll/move with horizontal scroll bar i want to see the datas that been in database(tables ) in the c# windows form.
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. using System.Configuration;
  12.  
  13. namespace DRRS_in_Csharp
  14. {
  15.     public partial class Technician : Form
  16.     {
  17.         long pUserID;
  18.         public Technician()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void Technician_Load(object sender, EventArgs e)
  24.         {
  25.             dtDOB.MaxDate = dtDOB.Value;
  26.             SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan16;Integrated Security=true");
  27.             if (conn.State != ConnectionState.Open)
  28.             {
  29.                 conn.Open();
  30.             }
  31.             SqlCommand cmd = new SqlCommand();
  32.             cmd.Connection = conn;
  33.             cmd.CommandType = CommandType.Text;
  34.             DataTable dt = new DataTable();
  35.             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");
  36.             cmd = new SqlCommand(s1, conn);
  37.             if (dt.Rows.Count == -1)
  38.             {
  39.                 scrRec.Visible = true;
  40.                 long i = 0;
  41.                 do
  42.                 {
  43.                     i = (i + 1);
  44.                 } while (dt.Rows.Count == -1);
  45.                 scrRec.Maximum = Convert.ToInt32(i - 1);
  46.                 lblRecPos.Text = "Record Pos(1/" + i + ")";
  47.                 txtFname.Enabled = false;
  48.                 txtMname.Enabled = false;
  49.                 txtLname.Enabled = false;
  50.                 dtDOB.Enabled = false;
  51.                 cboSex.Enabled = false;
  52.                 txtFname.Text = cmd.Parameters.AddWithValue("technician_first_name", SqlDbType.VarChar).Value.ToString();
  53.                 txtMname.Text = cmd.Parameters.AddWithValue("technician_middle_name", SqlDbType.VarChar).Value.ToString();
  54.                 txtLname.Text = cmd.Parameters.AddWithValue("technician_last_name", SqlDbType.VarChar).Value.ToString();
  55.                 dtDOB.Value = Convert.ToDateTime(cmd.Parameters.AddWithValue("technician_dob", SqlDbType.Date).Value);
  56.                 if ((cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value is DBNull) && (Convert.ToBoolean(cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value == false.GetType())))
  57.                 {
  58.                     cmd.Parameters.AddWithValue("technician_type", cboTechType.SelectedIndex);
  59.                 }
  60.                 else
  61.                 {
  62.                     cboTechType.SelectedIndex = 0;
  63.                 }
  64.                 if (cmd.Parameters.AddWithValue("technician_sex", SqlDbType.VarChar).Value == "M")
  65.                 {
  66.                     cboSex.SelectedIndex = 0;
  67.                 }
  68.                 else
  69.                 {
  70.                     cboSex.SelectedIndex = 1;
  71.                 }
  72.             }
  73.             else
  74.             {
  75.                 scrRec.Visible = true;
  76.                 button1.Text = "Create";
  77.             }
  78.             conn.Close();
  79.         }
  80.  
  81.         private void button1_Click(object sender, EventArgs e)
  82.         {
  83.             if (button1.Text == "New")
  84.             {
  85.                 txtFname.Enabled = true;
  86.                 txtMname.Enabled = true;
  87.                 txtLname.Enabled = true;
  88.                 cboSex.Enabled = true;
  89.                 dtDOB.Enabled = true;
  90.  
  91.                 txtFname.Text = "";
  92.                 txtMname.Text = "";
  93.                 txtLname.Text = "";
  94.                 cboSex.SelectedIndex = -1;
  95.                 txtFname.Focus();
  96.                 button1.Text = "Create";
  97.             }
  98.             string dFieldName = "";
  99.             if (txtFname.Text.ToString().Trim() == "")
  100.             {
  101.                 dFieldName = "Please enter the technician first name";
  102.             }
  103.             else if (cboSex.SelectedIndex == -1)
  104.             {
  105.                 dFieldName = "Please select gender for technician";
  106.             }
  107.             else if (cboTechType.SelectedIndex == -1)
  108.             {
  109.                 dFieldName = "Please select technician type";
  110.             }
  111.             if (dFieldName.ToString().Trim() != "")
  112.             {
  113.                 MessageBox.Show(dFieldName);
  114.             }
  115.             SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan16;Integrated Security=true");
  116.             if (conn.State != ConnectionState.Open)
  117.             {
  118.                 conn.Open();
  119.             }
  120.             SqlCommand cmd = new SqlCommand();
  121.             cmd.Connection = conn;
  122.             cmd.CommandType = CommandType.Text;
  123.             cmd = new SqlCommand("insert into TECHNICIAN(technician_dob,technician_sex,row_upd_date,user_id)" + "Values(@technician_dob,@technician_sex,GetDate(),@user_id)", conn);
  124.             if (cboSex.SelectedIndex == 0)
  125.             {
  126.                 cmd.Parameters.AddWithValue("@technician_sex", SqlDbType.VarChar).Value = "M";
  127.             }
  128.             else
  129.             {
  130.                 cmd.Parameters.AddWithValue("@technician_sex", SqlDbType.VarChar).Value = "F";
  131.             }
  132.             cmd.Parameters.AddWithValue("@technician_dob", dtDOB.Value);
  133.             cmd.Parameters.AddWithValue("@user_id", pUserID);
  134.             cmd.ExecuteNonQuery();
  135.  
  136.             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);
  137.             cmd.Parameters.AddWithValue("@technician_first_name", txtFname.Text);
  138.             cmd.Parameters.AddWithValue("@technician_middle_name", txtMname.Text);
  139.             cmd.Parameters.AddWithValue("@technician_last_name", txtLname.Text);
  140.             cmd.Parameters.AddWithValue("@technician_type", cboTechType.SelectedIndex);
  141.             cmd.Parameters.AddWithValue("@status", true);
  142.             cmd.Parameters.AddWithValue("@user_id", pUserID);
  143.             cmd.ExecuteNonQuery();
  144.             ((MDIParent5)this.MdiParent).updateUserActivities(pUserID, 3, txtFname.Text + "technician detail was added successfully");
  145.             MessageBox.Show("Technician detail  was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
  146.             conn.Close();
  147.  
  148.  
  149.         }
  150.  
  151.         private void button2_Click(object sender, EventArgs e)
  152.         {
  153.             this.Close();
  154.         }
  155.  
  156.         private void scrRec_Scroll(object sender, ScrollEventArgs e)
  157.         {
  158.  
  159.             SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan16;Integrated Security=true");
  160.             if (conn.State != ConnectionState.Open)
  161.             {
  162.                 conn.Open();
  163.             }
  164.             SqlCommand cmd = new SqlCommand();
  165.             cmd.Connection = conn;
  166.             cmd.CommandType = CommandType.Text;
  167.             DataTable dt = new DataTable();
  168.  
  169.             lblRecPos.Text = "Record Pos(" + scrRec.Value + 1 + "/" + scrRec.Maximum + 1 + ")";
  170.             if (dt.Rows.Count == -1)
  171.             {
  172.                 txtFname.Enabled = false;
  173.                 txtMname.Enabled = false;
  174.                 txtLname.Enabled = false;
  175.                 dtDOB.Enabled = false;
  176.                 cboSex.Enabled = false;
  177.                 txtFname.Text = cmd.Parameters.AddWithValue("technician_first_name", SqlDbType.VarChar).Value.ToString();
  178.                 txtMname.Text = cmd.Parameters.AddWithValue("technician_middle_name", SqlDbType.VarChar).Value.ToString();
  179.                 txtLname.Text = cmd.Parameters.AddWithValue("technician_last_name", SqlDbType.VarChar).Value.ToString();
  180.                 dtDOB.Value = Convert.ToDateTime(cmd.Parameters.AddWithValue("technician_dob", SqlDbType.Date).Value);
  181.                 if ((cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value is DBNull) && (Convert.ToBoolean(cmd.Parameters.AddWithValue("technician_type", SqlDbType.Int).Value == false.GetType())))
  182.                 {
  183.                     cmd.Parameters.AddWithValue("technician_type", cboTechType.SelectedIndex);
  184.                 }
  185.                 else
  186.                 {
  187.                     cboTechType.SelectedIndex = 0;
  188.                 }
  189.                 if (cmd.Parameters.AddWithValue("technician_sex", SqlDbType.VarChar).Value == "M")
  190.                 {
  191.                     cboSex.SelectedIndex = 0;
  192.                 }
  193.                 else
  194.                 {
  195.                     cboSex.SelectedIndex = 1;
  196.                 }
  197.                 conn.Close();
  198.             }
  199.  
  200.  
i have tried coding for horizontal scroll bar but nothing seems to work. Can anyone help me please!
Dec 24 '13 #1
0 1215

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2887
by: Nishant | last post by:
I have a combo box with a horizontal scroll bar. (Used SetHorizontalExtent) The dropdown with horizontal scroll bar works fine when I have more items in the dropdown list. However when the number of items is less, the horizontal scroll bar comes over the last item. If there is only one item, I am not able to see that item because of Horizontal scroll.
2
7523
by: Boaz Ben-Porat | last post by:
Hi all Is there a way to simulate a click on a scrollbar (horizontal) of a FataGrid ? I need to programmatically scroll the grid to the right/left upon some condition, when the total width of the grid columns is greater then the grid`s rectangle. TIA
4
1988
by: André Nobre | last post by:
hi all... i have a listbox in a webform and i wanna know if there´s way to put horizontal scroll in it. I tried HorizontalScrollbar = True, like windows forms but it didn´t work. Anyone can help me? Thanks, André
3
2526
by: Vidds | last post by:
Hi Everyone, How come Server listbox control does not have a Horizontal Scroll Property? If any one has an idea how we add a Horizontal scroll to a listbox or dropdown list box it would be quite helpful.Thanks in advance Regards Vidds
2
5034
by: Sam | last post by:
I've researched and tried all the suggestions I've found and still haven't been able to get the horizontal scroll bar to appear in my combo box. I've tried setting the Column Widths property larger than the Width property and set the List Width property to Auto as someone suggested in another thread but it doesn't work. I give up. Please help. If more info is needed let me know. The rowsource is a simple query: SELECT ANSWER_TEXT
2
5851
by: Steve | last post by:
Hi All I want to prevent the Windows Tabcontrol from showing the horizontal scroll bar when the Number of Tabs exceeds the width of the control I use code in 2 buttons to control the scrolling, as the default scroll buttons are too hard to target on a Touch Screen How do I do this?
2
1544
by: Michael Richard | last post by:
Hi, I need a help from you. I'm writing device driver for 64 bit Windows Server 2008. I have code for 32 bit Windows Server 2008, its working fine on 32 bit. I need a help to port from 32 bit to 64 bit. Please help me out. Thanks a lot.
0
972
by: =?Utf-8?B?Tml0cmFt?= | last post by:
I have searched almost everywhere to find this info, but have not read it anywhere. Can I use Web Server 2008 if the only thing it does is to host a bunch of .PDFs for people to look at from the web? Using a SQL database, with a bunch of PDFs, then people access it from the web, and view the files. Isn't that using it properly?
1
9106
by: amuven | last post by:
Hi All, I need to put a horizontal scroll bar for 4 cells alone where my first cell in table should not contain any horizontal scroll bar . In clear, let us say there are 5 columns in my table i want to put horizontal scroll bar only for 2nd,3rd,4th and 5th column alone where my 1st column should not horizontal scroll bar . so that I can scroll only last 4 columns . Please some one provide me sample code as early as possible in doing...
1
4361
by: newbie009 | last post by:
How can I disable horizontal scroll in textbox for FireFox? Right now 1 textbox has vertical scroll and other textbox has horizontal scroll. It only looks like this on FireFox but it looks ugly. http://jumbofiles.com/example.gif I used this code but it only worked for IE not FireFox: style="overflow: scroll; overflow-y: scroll; overflow-x: hidden; overflow:-moz-scrollbars-vertical;" Basically I want only vertical scroll.
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9345
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8265
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6811
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.