How to Refresh Column data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael

    #1

    How to Refresh Column data

    Hi Everyone,
    I have added a new column to an existing table. This column is to calculate
    the total for an Line item. I'm setting as follows:
    DS.Tables(0).Co lumns.Add("Tota l", System.Type.Get Type("System.Do uble"),
    "UnitPrice * Quantity")
    I need to know if there is any way that I can refresh this column to force
    it to recalculate the value for that line. I'm trying to get it to update
    once the user enters a Qty value. Thanks for any info.
    Michael

  • Chris

    #2
    Re: How to Refresh Column data

    Michael wrote:[color=blue]
    > Hi Everyone,
    > I have added a new column to an existing table. This column is to calculate
    > the total for an Line item. I'm setting as follows:
    > DS.Tables(0).Co lumns.Add("Tota l", System.Type.Get Type("System.Do uble"),
    > "UnitPrice * Quantity")
    > I need to know if there is any way that I can refresh this column to force
    > it to recalculate the value for that line. I'm trying to get it to update
    > once the user enters a Qty value. Thanks for any info.
    > Michael
    >[/color]

    Since a DataTable column can not contain a formula you can not do this
    as you are thinking. What you can do is add an event to your Qty column
    so that when the user changes the value you write code to update your
    new column.

    Something like:
    addhandler DS.Tables(0).Co lumnChanged, Addressof Column_Changed

    Private Sub Column_Changed( sender As Object, e As DataColumnChang eEventArgs)
    'Update your new column here
    End Sub

    Hope it helps
    Chris

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: How to Refresh Column data

      Michael,

      I don't think it the nicest solution, however when you find nothing better.
      (the problem is that the data is normaly pushed in the datatable at the
      moment when there is a rowchange)

      You can of course as well use styles and than use the event of the
      datagridtextbox to let the endcurrentedit push the data in the datatable..

      However this is very simple to do.

      \\\needs only a datagrid on a form and pasting in this code.
      Private Sub Form1_Load(ByVa l sender As Object, _
      ByVal e As System.EventArg s) Handles MyBase.Load
      Dim ds As New DataSet
      Dim dt As New DataTable
      ds.Tables.Add(d t)
      dt.Columns.Add( "Quantity", GetType(System. Double))
      dt.Columns.add( "UnitPrice" , GetType(System. Double))
      dt.Columns.Add( "Total", GetType(System. Double), "UnitPrice *
      Quantity")
      dt.LoadDataRow( New Object() {2, 4}, True)
      DataGrid1.DataS ource = ds.Tables(0)
      End Sub
      Private Sub DataGrid1_Paint (ByVal sender As Object, _
      ByVal e As System.Windows. Forms.PaintEven tArgs) Handles DataGrid1.Paint
      BindingContext( DirectCast(Data Grid1.DataSourc e,
      DataTable)).End CurrentEdit()
      End Sub
      ///

      I hope this helps,

      Cor



      Comment

      Working...