Results 1 to 8 of 8

Thread: Textbox value to datagridview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    Textbox value to datagridview

    can someone give me a sample code on how to add textbox values to a datagridview. I'm new to programming so bare with me.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Textbox value to datagridview

    Can you explain in a bit more detail what you're trying to achieve? Your question is rather general and any answer we give is quite likely to not apply to exactly what you're doing. Explain in terms of functionality, not code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    Re: Textbox value to datagridview

    basically what im trying to make is a point of sale application (Learning purposes only) I have multiple textboxes that are linked to an access database. When I click on a dropdown box I can select a product number, and all the textboxes are automaticly filled with the correct matching data. Ex. Description, size, color. <---This I'm able to do.

    From here is where I have the problem.

    Not able to do ---> After selecting the item I would click on the addButton and it would populate the datagridview with the item selected, calculate the prices. From there I can continue to add more items to the datagridview, or I can click done and have the item saved in its own table with a transaction # as the primary key.

    This I can do --->In the future I would be able to look up transactions

    Hopefully this makes sense

    Thanks for the help

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Textbox value to datagridview

    As you haven't specified I'm going to assume that your grid is bound to a BindingSource and that that BindingSource is bound to a DataTable. In that case you would call the AddNew method of the BindingSource to create a new DataRowView. You'd set the fields of that row and then end the editing session to push it to the underlying table, e.g.
    C# Code:
    1. DataRowView row = (DataRowView)myBinsingSource.AddNew();
    2.  
    3. row("ID") = myComboBox.SelectedValue;
    4. // Set other fields here, e.g. quantity.
    5.  
    6. myBindingSource.EndEdit();
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    Re: Textbox value to datagridview

    Code:
            private void addButton_Click(object sender, EventArgs e)
            {
               
                DataRowView row = (DataRowView)invoiceBindingSource.AddNew();
                row("Invoice") = invoiceCountInteger;
                row("Desc") = descTextBox.Text;
                row("PartID") = partIDComboBox.Text;
                invoiceBindingSource.EndEdit();

    I'm getting this error

    Error 1 'row' is a 'variable' but is used like a 'method'


    What am I doing wrong? BTW im using Access MDF database if that makes any difference.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Textbox value to datagridview

    Ah, sorry. Showing my VB.NET bias there. Whenever you index an array or collection in C# you use square brackets. My previous code should have been:
    Code:
    row["ID"] = myComboBox.SelectedValue;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    Re: Textbox value to datagridview

    Thanks for you help this worked. Can you give me a sample code on how to use the update method to save this to the db file.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Textbox value to datagridview

    Check this out and use an online code converter to convert it to C#. Having said that, if you actually look at the code and read it you should be able to understand most, if not all, of it. C# and VB.NET are not so different that most code isn't almost the same.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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