Results 1 to 5 of 5

Thread: requiring code for c#

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Posts
    22

    requiring code for c#

    hi , i am making a windows form application through c# ,
    in that i am making some fields such as textbox and grid view.
    now , there is one table of employee which consist some column and first column is "EmployeeID".
    now , the employeid textbox is dropdown having items of column "EmployeeId" fetched from database table employee.

    my problem is , how to bound my employee id textbox to database table employee column "EmployeeID".

    plz give the code .

  2. #2
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: requiring code for c#

    Give you code? No chance. You won't learn if I write code for you.

    Try starting here: http://dotnetaid.com/2011/08/23/data...c-net-winform/

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Posts
    22

    Re: requiring code for c#

    sir , i already done these things and in a very advanced level , i done all the functionality , whatever u given is at very basic level .
    my project is completed but only this fuctionality is not there such that if the user click the drop down arrow of txtbox employee id , the textbox starts showing all the values in datatable column employee id.
    atleast u can help me over here for this small thing.

  4. #4
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: requiring code for c#

    1) Create a combo box and populate it as such:
    a) Get a list of employees from your database and create an Employee object for each setting it's properties as required
    b) Use this list of employees to add items to your combo box


    Pseudo code:
    Code:
    foreach(Employee emp in EmployeeList)
    {
     1) set combo box item Tag property = emp and Text property = emp.Name (or whatever you want to be displayed to the user)
     2) add item to combo box
    }
    2) Databind your grid view to the employee list (all items)
    3) On the selected index changed event of the combo box do the following:
    a) Get an Employee object from the Tag (Employee myEmp = (Employee)item.Tag)
    b) Use a linq query on the original list using the myEmp.Id property as such

    List<Employee> myEmps = empList.Where(emp => emp.Id = myEmp.Id)

    c) use this list to databind your grid view again, this will allow you to achieve filtering as you specify



    I'll let you write the code, you can Google most of the things i've said to get examples.

    This is by no means the best solution. But it will do what you want and is fairly easy to implement.

  5. #5
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: requiring code for c#

    I'm assuming you mean you have a ComboBox that you want bound to a column in your database.

    1. Get the data in a DataTable.

    2. Set the .DataSource, .DisplayMember and .ValueMember properties of the ComboBox.
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width