473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Datagridview Calculation

dear all,
I am very new to vb.net 2. This is my post to this site. I have some
doubts in Datagridview.
I am using datagridview in unbound mode. in datagridview i have 4
coloumns

product qty price amount

product coloumn is a combo box and others textbox. now when i enter
leave qty or price i want the amount to be calculated and displayed
automatically. below is the code which i used

but when leaving the price coloumn the amount is not calculating. if i
back to qty and pressing tab again it is calculating

code..

Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellLeave
If (TypeOf CType(sender,
Windows.Forms.DataGridView).EditingControl Is
DataGridViewComboBoxEditingControl) Then
DataGridView1.EditingPanel.Select()
End If
If e.ColumnIndex = 1 Or e.ColumnIndex = 2 Then
DataGridView1.Rows(e.RowIndex).Cells(3).Value =
CType(DataGridView1.Rows(e.RowIndex).Cells(1).Valu e *
DataGridView1.Rows(e.RowIndex).Cells(2).Value, Double)
End If
End Sub

can anybody help me in this ...

thanks

Mar 15 '07 #1
1 3665
Instead of trying to change the 3rd value when any of the 2 other
values change, you could just try to compute the 3rd anytime it is
needed by the DataGridView. Handling these events tries to do this.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
EventArgs) Handles MyBase.Load
DataGridView1.RowCount = 10
DataGridView1.ColumnCount = 4

End Sub

Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object,
ByVal e As DataGridViewCellCancelEventArgs) Handles
DataGridView1.CellBeginEdit
If e.ColumnIndex = 3 Then
e.Cancel = True
End If
End Sub

Private Sub DataGridView1_CellFormatting(ByVal sender As Object,
ByVal e As DataGridViewCellFormattingEventArgs) Handles
DataGridView1.CellFormatting
If e.ColumnIndex = 3 AndAlso e.RowIndex -1 Then
e.Value = Convert.ToDouble(DataGridView1(1,
e.RowIndex).Value) * Convert.ToDouble(DataGridView1(2,
e.RowIndex).Value)
End If
End Sub
Private Sub DataGridView1_CellValidated(ByVal sender As Object,
ByVal e As DataGridViewCellEventArgs) Handles
DataGridView1.CellValidated
DataGridView1.Refresh()
End Sub

=====================
Clay Burch
Syncfusion, Inc.

Mar 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Art | last post by:
Hi, I'm having some trouble with my DataGridView. I have it bound to a DataTable. One column of the grid is a boolean that says whether a row should be visible. There is also a checkbox...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
1
by: enrico via DotNetMonster.com | last post by:
can you input a field in a datagridview that can be save to your database? can you make a calculation on it? please tell me how. -- Message posted via DotNetMonster.com...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.