I am new to Visual Basic 6.0 and need help with the DataGrid control.

I am trying to:
1. Have data in one of the grid column's that is in "lower case" forced to "upper case"
I have tried using the Before Update event, but cannot get it to work.
2. Have column validate data. Only allow for example an "A" or "C" as valid values for a column.
3. Put in "tips" on top of each column to display information about the column itself.

I have searched the web and looked in 3 book stores and cannot find books with Datagrid examples for what I need.

Any help would be greatly appreciated.

Thanks.

Scott

Dani AI

Generated

Quick, VB6-specific roadmap for the three items asked by . posted .NET links and correctly noted those are for VB.NET; the patterns below are for classic VB6/ADO.

  • Force uppercase

    • Best place: the database. Add a trigger or a computed/normalized column (or use an INSERT/UPDATE trigger) so all data is forced to UPPER() server-side. This guarantees consistency from any client.
    • Client-side: catch keystrokes in the grid editor and convert as typed (for example, in KeyPress change KeyAscii = Asc(UCase$(Chr$(KeyAscii)))). This is simple and immediate, but it does not handle paste or programmatic updates.
    • Recordset post-processing: when using ADO, sink the Recordset events (WithEvents) and normalize values in the field-change events (WillChangeField / FieldChangeComplete). Use a boolean guard to avoid recursive updates when you write back the transformed value.
  • Per-column validation (only allow 'A' or 'C')

    • Enforce in the database with a CHECK constraint — the most robust solution.
    • UI pattern in VB6: show a small ComboBox overlay for that grid cell. On cell activate, position a hidden ComboBox over the cell, fill it with the allowed values ('A','C'), let the user pick and write the value back to the recordset. This avoids fiddly event-cancels and gives a clean UX.
    • Simpler quick check: validate in the recordset change event and, if invalid, restore the previous value and inform the user. Again use a guard flag to prevent re-entrancy.
  • Column "tips" (tooltips on headers)

    • The DataGrid has no built-in header-tooltips. Two practical approaches:
      • Put a row of Label controls above the grid (one per column) and use their ToolTipText property for the tips.
      • Use a ToolTip control and detect mouse X over the header area (sum column widths to map X to column), then show the appropriate tip. Cache column left positions for fast lookup.

Notes: prefer server-side enforcement for integrity, and mirror with client-side checks for better UX. If the project uses ADODB/ADODC, the WithEvents + Recordset event pattern is the usual VB6 route for post-change validation and normalization; when using it, watch for recursion and update loops.

Recommended Answers

All 2 Replies

all over the web?

this was the first hit in google for "datagrid"

and microsoft calls it "ItemStyle" in their page
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsdatagridclassitemstyletopic.asp

here's another upper case datagrid reference
http://www.dotnet4all.com/dotnet-code/2004/12/datagrid-uppercase-and-sort.html

all the best...

Actually, The second and third link refers to the .NET platform, which would be vb.net. This particular forum is for Legacy Versions of VB (Mostly VB6). He also says that he's new to Visual Basic 6, and so the syntax in .NET would be of no help to him. But Thumbs up on the references.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.