Changing datagrid values - HELP!!

I have a datagrid (Win forms) and I have added an expression column as follows: 

DS_Book1.Tables("HaulageBooking").Columns.Add("EstPall", _ 
      Type.GetType("System.Double"), "OrderQuantity / DefaultOPP") 


The I add column to gridtablestyle: 

Dim colEstPallets As DataGridTextBoxColumn = New DataGridTextBoxColumn() 
      With colEstPallets 
        .MappingName = "EstPall" 
        .HeaderText = "Estimated Pallets" 
        .Alignment = HorizontalAlignment.Left 
        .Width = IntAvgCharWidth * 12 
        .NullText = "None" 
        .ReadOnly = True 
      End With 
GridTableStyle.GridColumnStyles.Add(colEstPallets) 


I want to be able to have the value in this column change when I enter a value in another column. Getting desperate on this one now! Appreciate any help. 

How is this done  Would I have to change the value in the datatable then refresh the grid or can i change it straight in the grid which in turn updates the table

thanks 

KS 


Answer this question

Changing datagrid values - HELP!!

  • Sean Hunt

    I am still not able to get this working properly. The code:
    DS_Book1.Tables("HaulageBooking").Columns("EstPall").Expression = ("OrderQuantity / OverrideOPP") 

    I think this operates the expression on all rows. I only want it to work on the current row. Someone suggested the ColumnChange event, but i have no idea how to implement that. IF someone knows please feel free to tell me!

    Your help will be very much appreciated.

    thanks,

    KS

  • Rdan

    okay, i can change the cell now - but my code has a side affect...

    Private Sub DG_Book_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DG_Book.CurrentCellChanged
            With DG_Book
                If Not IsDBNull(.Item(.CurrentRowIndex, 23)) Then
                    With .CurrentRowIndex
                         DS_Book1.Tables("HaulageBooking").Columns("EstPall").Expression = ("OrderQuantity / OverrideOPP")
                    End With
                End If
            End With
    End Sub

    I have 3 columns  with these values

    Qty  |  DefaultOPP  |  Override OPP  |  EstPall
    ------------------------------------------------------
    100     50                    none                 2
    100     20                    none                 5



    What I want is for "EstPall" to change when I enter a value in "Override OPP", otherwise I do NOT want it to change. The text "none" is from .nullText.Value

    My code is currently doing this but it is also reverting the "EstPall" value to "none" when I click on those columns/rows.  Should I be using the OnCellChanged event  Can I use something like the KeyUp event and then maybe change it on "Enter" key press

    Thanks in advance,


    KS

  • Changing datagrid values - HELP!!