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

Posted on 2005-03-28
Medium Priority
Last Modified: 2010-05-18
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
            <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.AllowUpdate = False
            Grid.AllowUpdateOnBlur = False


        '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)
        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...
Question by:squallbsr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 96

Accepted Solution

Bob Learned earned 1500 total points
ID: 13645401
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?


Author Comment

ID: 13645554
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

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...)
LVL 96

Expert Comment

by:Bob Learned
ID: 13646024
Example of an expression DataColumn from http://www.dotnetspider.com/Question751.aspx:

dc.Expression = " CashExp * Frequency"

dc = New DataColumn("AnnualCredit", GetType(System.Single))
dc.Expression = " CreditExp * Frequency"


Author Comment

ID: 13675523
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...

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question