PDA

Click to See Complete Forum and Search --> : Textbox value to datagridview


mrman99
May 22nd, 2007, 03:27 PM
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.

jmcilhinney
May 22nd, 2007, 06:42 PM
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.

mrman99
May 22nd, 2007, 06:56 PM
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

jmcilhinney
May 22nd, 2007, 08:39 PM
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.DataRowView row = (DataRowView)myBinsingSource.AddNew();

row("ID") = myComboBox.SelectedValue;
// Set other fields here, e.g. quantity.

myBindingSource.EndEdit();

mrman99
May 23rd, 2007, 12:56 AM
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.

jmcilhinney
May 23rd, 2007, 03:03 AM
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:row["ID"] = myComboBox.SelectedValue;

mrman99
May 23rd, 2007, 03:49 PM
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.

jmcilhinney
May 23rd, 2007, 06:43 PM
Check this (http://www.vbforums.com/showthread.php?t=469872) 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.