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.
Printable View
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.
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.
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
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();
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.
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;
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.
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.