+ Reply to Thread
Results 1 to 5 of 5

Thread: Basic Data Binding in C#

  1. #1
    Speaks fluent binary zeroradius will become famous soon enough zeroradius's Avatar
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,174

    Basic Data Binding in C#

    EDIT: If you would prefer to watch this as a video go to this link: Basic Data Binding In C# | Screencast-O-Matic


    Basic Data Binding in C#

    Step 1: Create a new windows C# form and name it contactBookV1

    Basic Data Binding in C#-pic1.jpg



    Step 2: (Optional) Size your form up a bit by clicking on it in the design window and dragging it up and out

    Step3: (Optional) Select the form in the designer and change the text filed in the properties window to “Contact Book V.1” This will change the text at the top of the form

    Basic Data Binding in C#-pic2.jpg


    Step4: Create a new Data base by going to Project >> Add New Item

    Basic Data Binding in C#-pic3.jpg



    Step4 (Continued): Chose Service-Based Database and name it MyContacts.

    Basic Data Binding in C#-pic4.jpg



    Note: Hit the Cancel button on the Data Source Configuration Wizard.


    Step5: Right Click on Tables in the Server Explorer Pane (Database Explorer if you are using Express addition) and Select Add New Table from the submenu

    Basic Data Binding in C#-pic5.jpg



    Step6: Create your Table by following the below Schema

    Basic Data Binding in C#-schema.jpg


    Note: Set Primary key by selecting the desired cell and hitting the key up on the menu

    Basic Data Binding in C#-pic6.jpg



    To make it Auto Increment, go to the Column Properties, Under Identity Specification, set (Is Identity) to yes.

    Basic Data Binding in C#-pic7.jpg


    (If the c_id filed is not set up correctly your program will crash when you try to use certain features)


    Step7: On the menu under file select Save All. Name the database contacts.


    Step8: Create a new Database Diagram by right clicking the database diagram in the Server / Database Explorer and selecting new Diagram

    Basic Data Binding in C#-pic8.jpg



    The below window will pop up. Select “Yes”

    Basic Data Binding in C#-pic9.jpg


    A new table will pop up titled “Add Table” Select Contacts from the list and hit Add

    Basic Data Binding in C#-pic10.jpg


    Save the Diagram as contactsDiagram


    Step9: Go back to the Form1.cs *design* tab. From the menu bar select Data >> Add New Data Source

    Basic Data Binding in C#-pic11.jpg


    Select Database from the new popup window. Proceed to hit the next button until you get to the final page. On the last page check all the check boxes and hit finish.

    Step 10: Go to the Data Source Pane and expand the field called Contacts so that you see all the cell names from your database. click on Category and then click on the silver down arrow that appears next to it. Select Combo box from the menu that appears.

    Basic Data Binding in C#-pic12.jpg


    Step11: Left Click on each filed in turn and drag it onto the windows form (Do not put c_id on the form) and put them in some type of pattern. You can change the lable to each control the same way we changed the forms text in Step 3 (Note: Make sure you select the lable [Black text] Not the text box [white box])


    Your form should now look like this:

    Basic Data Binding in C#-pic13.jpg


    Step12: left click the combo box for category on your form. Chose Items from the properties pane and enter in the values Friend, Business, and Other then hit OK button

    Basic Data Binding in C#-pic14.jpg



    Step13: Save your work and hit F5, everything should work except saving. You will have to Create a setup to do that.

    Step14: Time to create that install so everyone can use your application. Select Build on the menu than select Publish contactBookV1 from the submenu.

    Basic Data Binding in C#-pic15.jpg


    Hit finish on the window that pops up to accept all the defaults.

    Inside your project folder you will find a folder called Publish. Grab all of its content and copy it to a disk. Go install it on a computer and go crazy ^_^

    (Ehh I think I got all the images in the right spot. If every thing wasnt clear I apologise, this is my first tut.)
    Last edited by zeroradius; 08-11-2009 at 10:40 AM.

  2. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,750
    Blog Entries
    97

    Re: Basic Data Binding in C#

    Awesome tutorial! I love the screenshots, looks like you spent some time on them. Nice work. +rep

  3. #3
    Programming Professional Parabola will become famous soon enough Parabola will become famous soon enough Parabola's Avatar
    Join Date
    Jul 2009
    Location
    Texas
    Age
    26
    Posts
    305
    Blog Entries
    3

    Re: Basic Data Binding in C#

    ..... well.... I was literally about to post a very similar tutorial.. and you beat me to it. Nice work, I'm going to +rep, but unfortunately I don't have much rep power yet

    Reason for my program was that I was having to constantly go into SQL and lookup parts to get price and description data, so I wrote a quick app to do that for me. Was also going to include this in the tutorial, which may still be useful to anyone else:

    Code:
            private void getData()
            {
                try
                {
                    this.inventory_pricingTableAdapter.Fill(this.marksDataSet.inventory_pricing, partNumToolStripTextBox.Text);
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
    
            private void partNumToolStripTextBox_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == 13)
                {
                    getData();
                }
            }
    Everyone should get the idea- If you press enter on a text entry box, it does getData()


    Still, Nice work, well done.
    Programmer (n): An organism that can turn caffeine into code.
    Programming would be so much easier without all the users.

  4. #4
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    37
    Posts
    13,155
    Blog Entries
    59

    Re: Basic Data Binding in C#

    Nicely done. I love step-by-step stuff (and concept stuff)
    CodeCall Blog | CodeCall Wiki
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #5
    Speaks fluent binary zeroradius will become famous soon enough zeroradius's Avatar
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,174

    Re: Basic Data Binding in C#

    EDIT: I made a video tutorial using better software. See my first post for the link


    Thanks guys ^_^ I origonaly did it as a video tutorial but the screencast software I am using (CamStudio) starts to lag after a while so that my naration dosent match with the video so I decided to do it the long way.
    Last edited by zeroradius; 08-11-2009 at 10:41 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. C#:Tutorial - Download Data
    By Xav in forum CSharp Tutorials
    Replies: 15
    Last Post: 08-02-2010, 11:46 PM
  2. Understanding Basic Data Types
    By WingedPanther in forum C Tutorials
    Replies: 10
    Last Post: 06-01-2010, 05:10 AM
  3. Choosing the right language / data structure / Interface
    By ups in forum General Programming
    Replies: 1
    Last Post: 09-20-2008, 06:11 AM