Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2296
  • Last Modified:

Bound True DBGrid .NET: Adding Columns & Computed Values to the Grid itself.

I have the .NET version of the True DBGrid control (v.1.3.20051.41221) and am trying to add columns to the grid in addition to what is already in the DataTable.  I have added the columns using the Control Designer, so the columns exist and are blank since they cannot be bound to any field in the datatable.  I have tried this method in trying to get it to work.  (Example is in VB.NET).

    Public Shared Sub SetupPOEIAuthsGrid(ByVal db As AppDatabase, ByRef Grid As C1.Win.C1TrueDBGrid.C1TrueDBGrid)
        'Enable grid layout
        If PETApp.LoadGridSchema(Grid, "poeiauthorization") Then
            'Grid is loaded
        Else
            <snip> (error catching for when schema isn't loaded)
        End If


        'Figure Manpower Totals for each authorization
        'Dim x As Integer
        For x As Integer = 0 To Grid.VisibleRows - 1
            Grid.Row = x
            Grid.AllowUpdate = True
            Grid.AllowUpdateOnBlur = True
            'Deal with each MQ column
            Dim Cols As C1.Win.C1TrueDBGrid.C1DataColumnCollection
            Cols = Grid.Columns
            Cols("MQ0").Text = "0"                      <-- Attempt #1
            Cols("MQ1").Text = 1                        <-- Attempt #2
            Cols("MQ2").Text = 2
            Cols("MQ3").Text = 3
            Cols("MQ3").RefreshCell()                  <-- Desparate Attempt

            Grid.Item(x, "MQ4") = 4                     <-- Attempt #3
            Grid.Item(x, "MQ5") = 5
            Grid.Item(x, "MQ6") = 6
            Grid.Item(x, "MQ7") = 7

            Grid.MoveFirst()                                <-- More desparate Attempts
            Grid.Refresh()

            Grid.AllowUpdate = False
            Grid.AllowUpdateOnBlur = False

        Next

        'Titles to current quarters
        'Don't change the titles before the Manpower totals are computed.
        Grid.Columns("CQ0").Caption = Quarter.AddQuarter(db.DBQuarter, 0)
        Grid.Columns("MQ0").Caption = "M" & Quarter.AddQuarter(db.DBQuarter, 0)
        <snip>
        Grid.Columns("CQ7").Caption = Quarter.AddQuarter(db.DBQuarter, 7)
        Grid.Columns("MQ7").Caption = "M" & Quarter.AddQuarter(db.DBQuarter, 7)

    End Sub

The setting of the captions work correctly, I get no errors thrown or anything.  The grids just sit there looking at me with a blank stare...  The CQ(x) columns are bound to the datatable, the MQ(x) are supposed to be computed values (The example just has numbers, i'll replace with actual computed values if I can get this to work.)

Any ideas on how to fix this?  It is kinda time sensitive because our customer is breathing down our necks because of the time schedule...
0
squallbsr
Asked:
squallbsr
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
You can create calculated expression columns to the dataset, and bind them the same way that you bind the regular columns.

What is a typical expression used in calculation?

Bob
0
 
squallbsrAuthor Commented:
The computed fields are actually taking an equipment quantity in a related table and multiplying it by equipment man-hours in another related table.

Small look at the database:
Equipment Table:
   Part Number
   Stock Number
   Equipment Man Hours
   ...

Authorizations Table:
   Organization Auth belongs to
   Which "set/grouping" of equipment Auth belongs to
   How many "Authorizations"
   ...

Authorized Equipment Table:
   Part Number
   Stock Number
   Quantity
   Authorization

Formula is: AuthorizedEquipmentTable.Quantity * AuthorizationsTable.HowManyAuths * EquipmentTable.ManHours

I'm thinking maybe a SQL View/Query (this is Access) would do the trick also - however that would be tricky SQL.  I'm more of a novice in the SQL department...  (Although, even I know that this thing should be in SQL Server/Oracle/etc...)
0
 
Bob LearnedCommented:
Example of an expression DataColumn from http://www.dotnetspider.com/Question751.aspx:

dc.Expression = " CashExp * Frequency"
myDataSet.Tables("ClientExpenses").Columns.Add(dc)

dc = New DataColumn("AnnualCredit", GetType(System.Single))
dc.Expression = " CreditExp * Frequency"
myDataSet.Tables("ClientExpenses").Columns.Add(dc)

Bob
0
 
squallbsrAuthor Commented:
Alright, thank you for your input.

I got it to work by adding a column to the dataset, however I have problems with the Grid the very first time I open the Grid and apply the schema.  Unfortunately the grid is bound to the database before I build and add the new column, the grid has no layout applied yet.  I add the column, then add a layout to the grid and only the very first time the grid is displayed does it show none of the values that are in the new column.  Every single time that particular form is opened again - the values display properly.  I even tried Grid.ReBind() and if I don't use a layout at all, it works.  Something is weird with the layout system of True DBGrid.NET.

My recommendation is to stay away from True DBGrid.NET.  It has been nothing but problems...

Adding a DataColumn to the DataSet was the answer...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now