Solved

adjust the texbox total value

Posted on 2009-03-31
9
192 Views
Last Modified: 2013-11-05
hi..
I have an editable datagrid that contains on 3 columns (unit_price, qty, price),
and I have one textbox (txtTOTAL) to count all rows of the price column,

what I want is when the user edit the value of any price cell in the datagrid, the (txtTOTAL) will adjust depends on the changes.

thanks
0
Comment
Question by:Jassimi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:cdaly33
ID: 24028748
You should able to capture it like this:

  Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
    Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
    Dim cell As DataGridViewCell = row.Cells(e.ColumnIndex)
 
    Dim mynewvalue = cell.Value
 
    txtbox.text = txtbox.text + mynewvalue
  End Sub

Open in new window

0
 
LVL 2

Author Comment

by:Jassimi
ID: 24029224

cdally33,
when I put your code I'm getting this error:
Conversion from String "" to type 'Double' is not valid. Source: Microsoft.VisualVasic
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24029270
sounds like your cell value doesn't have a value at that point.  to get around that you can do something like this:
  Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
    Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
    Dim cell As DataGridViewCell = row.Cells(e.ColumnIndex)
 
    Dim mynewvalue = cell.Value
 
if isnumeric(mynewvalue) then
    txtbox.text = txtbox.text + mynewvalue
end if
 
  End Sub

Open in new window

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 2

Author Comment

by:Jassimi
ID: 24029554

what do you mean by (e.RowIndex)
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24029600
e.RowIndex is the 0-based index number of row being edited

here you'd be using it to retrieve the row containing the edited cell
0
 
LVL 2

Author Comment

by:Jassimi
ID: 24030288

I still facing same error,
the other thing is that I don't want number of row to be fixed..
because sometime when I make search in the datagrid, the rows required will appear and after that I will edit the values
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24032248
I'm confused then about what your end result needs to be.  Sorry.
0
 
LVL 2

Author Comment

by:Jassimi
ID: 24036322
any body can help ?
0
 
LVL 2

Accepted Solution

by:
Jassimi earned 0 total points
ID: 24038352
ok..
I got the solution
we have to write the following code in CellEndEdit event:
Dim Sum_ As Integer = 0
        With DataGridView1
            For i As Integer = 0 To .Rows.Count - 1
                Sum_ += .Rows(i).Cells("NumInGridView").Value
            Next
            txtSum.Text = Sum_
        End With


it will work fine after any changs in datagrid values

thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question