|
-
May 22nd, 2007, 03:27 PM
#1
Thread Starter
Junior Member
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.
-
May 22nd, 2007, 06:42 PM
#2
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.
-
May 22nd, 2007, 06:56 PM
#3
Thread Starter
Junior Member
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
-
May 22nd, 2007, 08:39 PM
#4
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:
DataRowView row = (DataRowView)myBinsingSource.AddNew();
row("ID") = myComboBox.SelectedValue;
// Set other fields here, e.g. quantity.
myBindingSource.EndEdit();
-
May 23rd, 2007, 12:56 AM
#5
Thread Starter
Junior Member
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.
-
May 23rd, 2007, 03:03 AM
#6
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;
-
May 23rd, 2007, 03:49 PM
#7
Thread Starter
Junior Member
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.
-
May 23rd, 2007, 06:43 PM
#8
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|