Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Dim table As New DataTable
        da.Fill(table)
        table.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox5.Text)
        DataGridView1.DataSource = table


What I have tried:

How to add value in datagridview from textbox and I want to add same product price 10. If they are already added then cells total become 20.
How to achieve this functionality?
Posted
Updated 20-Oct-16 21:24pm
Comments
[no name] 20-Oct-16 11:50am    
You convert the strings to numbers and add them.
CaptainChizni 20-Oct-16 11:56am    
do you have a code for this? I'm really new to this
[no name] 20-Oct-16 12:03pm    
Doing research, reading documentation, and attempting your work is how you learn. Could I write the code for you? Sure, but then you won't learn anything other than someone will do your work for you.
Ralf Meier 21-Oct-16 1:23am    
I the reply of NotPoliticallyCorrect right ? Do you want to add the values of the 5 Textboxes and write the result of this Addition into a new cell of your DataTable ?
Or is your requirement different ?
CaptainChizni 21-Oct-16 1:43am    
Yes i want to add the values of the 5 textboxes and write the result of this additon into a new cell of my datatable

1 solution

As I wrote in my Comment :
VB
Dim mySum as double = cdbl(TextBox1.Text) + cdbl(TextBox2.Text) + cdbl(TextBox3.Text) +cdbl(TextBox5.Text)
table.Rows.Add(mySum.toString)


But note :
Each Textbox-Value MUST be able to be converted. If it is possible that there is a non-decimal value in it you should handle it.
the Result mySum has no Formatting - but toString gives you the ability to do this - see MSDN-Help for this ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900