I have scoured and cannot understand this issue. I have a datagridview that I'm binding on form load as follows:
Dim sql As String = "SELECT PartNo, PartName, UnitQOH, QtyOH FROM tblInvQty ORDER BY PartName ASC"
Dim sCommand As New SqlCommand(sql, connection.sqlSBO)
Dim sAdapter As New SqlDataAdapter(sCommand)
Dim sBuilder As New SqlCommandBuilder(sAdapter)
Dim sDs As New DataSet()
Dim sTable As DataTable = sDs.Tables("Qty")
connection.sqlSBO.Open()
sAdapter.Fill(sDs, "Qty")
connection.sqlSBO.Close()
DataGridView1.DataSource = sDs.Tables("Qty")
DataGridView1.ReadOnly = False
DataGridView1.Columns(0).ReadOnly = True
DataGridView1.Columns(1).ReadOnly = True
DataGridView1.Columns(2).ReadOnly = True
DataGridView1.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
DataGridView1.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
DataGridView1.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
DataGridView1.Columns(2).HeaderText = "Current QOH"
I then want to add an unbound column, just as a reference. I'm using the following immediately after the above listed code:
DataGridView1.Columns.Add("NewQOH", "New QOH")
DataGridView1.Columns(4).ReadOnly = True
DataGridView1.Columns(4).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
This column is used as a reference so as the invoice is entered, the new QOH should adjust, so they can see the increase in inventory. I am adjusting the value on load, as such:
Dim i As Integer
For i = 0 To Me.DataGridView1.Rows.Count - 1
DataGridView1.Rows(i).Cells("NewQOH").Value = (DataGridView1.Rows(i).Cells("QtyOH").Value + DataGridView1.Rows(i).Cells("UnitQOH").Value)
Next
This ALL works fine. Until I want to update the New QOH with the amount entered in the QtyOH cell. I have searched and searched and it seems the following code, from what I'm seeing, should do it:
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
UpdateQOH()
End Sub
where UpdateQOH() is:
Private Sub UpdateQOH()
Dim rowNum As Integer
rowNum = DataGridView1.CurrentRow.Index
DataGridView1.Item(4, rowNum).Value = (DataGridView1.Item(3, rowNum).Value + DataGridView1.Item(2, rowNum).Value)
End Sub
If I use UpdateQOH in the CellValueChanged event, my new column disappears from the grid completely. However, if I just comment out the function, so it doesn't run, the column shows fine, and the math is correct. I can't for the life of me, figure out how to update the corresponding cell, when a new QOH is entered. My column keeps disappearing. I was going to just add the entered amount to "UnitQOH", however I was hoping to show them a before and after: here was your OH, here is your entry, this should be the new OH.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.