Solved

Binding Data to Grid

Posted on 2010-08-24
9
379 Views
Last Modified: 2012-05-10
Hi,

I'm sure it a simple one...

I have a Grid on a form and right below Grid there are few CheckBoxes. The questions are:

  - How do I select a Row in the Grid? when I select it should select whole Row and in a different color.
  - On selection of a Grid Row it should display the CheckBoxes status for the current Row selected.

Thanks!
SP
0
Comment
Question by:Nick Sui
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:tusharkanvinde
Comment Utility
Maybe you want to set the HighlightRow property of the grid

Change the controlsource of the checkboxes to the field that it is supposed to be linked to. If you do not want to allow the user to change the value, make the checkbox readonly. Then refreshing the checkbox will change the value as the value of the field changes. You can refresh the checkbox in the AfterRowColChange event of the grid. You can refresh it only when the RowColChange property of the grid is 1 or 3. You could put all the checkboxes in a container and refresh the container instead of refreshing each checkbox one by one
0
 
LVL 35

Author Comment

by:Nick Sui
Comment Utility
Can you please post a working example?

Thanks
SP
0
 
LVL 14

Expert Comment

by:tusharkanvinde
Comment Utility
DEFINE CLASS form1 AS form


      Top = -1
      Left = 1
      Height = 562
      Width = 997
      DoCreate = .T.
      Caption = "My VFP Form"
      Name = "Form1"


      ADD OBJECT grid1 AS grid WITH ;
            ColumnCount = 3, ;
            Height = 361, ;
            Left = 84, ;
            RecordSource = "temp", ;
            Top = 60, ;
            Width = 733, ;
            Name = "Grid1", ;
            Column1.ControlSource = "temp.fld", ;
            Column1.Name = "Column1", ;
            Column2.ControlSource = "temp.check1", ;
            Column2.Name = "Column2", ;
            Column3.ControlSource = "temp.check2", ;
            Column3.Name = "Column3"


      ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
            Caption = "Header1", ;
            Name = "Header1"


      ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
            BorderStyle = 0, ;
            Margin = 0, ;
            ForeColor = RGB(0,0,0), ;
            BackColor = RGB(255,255,255), ;
            Name = "Text1"


      ADD OBJECT form1.grid1.column2.header1 AS header WITH ;
            Caption = "Header1", ;
            Name = "Header1"


      ADD OBJECT form1.grid1.column2.text1 AS textbox WITH ;
            BorderStyle = 0, ;
            Margin = 0, ;
            ForeColor = RGB(0,0,0), ;
            BackColor = RGB(255,255,255), ;
            Name = "Text1"


      ADD OBJECT form1.grid1.column3.header1 AS header WITH ;
            Caption = "Header1", ;
            Name = "Header1"


      ADD OBJECT form1.grid1.column3.text1 AS textbox WITH ;
            BorderStyle = 0, ;
            Margin = 0, ;
            ForeColor = RGB(0,0,0), ;
            BackColor = RGB(255,255,255), ;
            Name = "Text1"


      ADD OBJECT container1 AS container WITH ;
            Top = 432, ;
            Left = 132, ;
            Width = 325, ;
            Height = 61, ;
            Name = "Container1"


      ADD OBJECT form1.container1.check1 AS checkbox WITH ;
            Top = 12, ;
            Left = 84, ;
            Height = 17, ;
            Width = 60, ;
            Alignment = 0, ;
            Caption = "Check1", ;
            ControlSource = "temp.check1", ;
            Name = "Check1"


      ADD OBJECT form1.container1.check2 AS checkbox WITH ;
            Top = 12, ;
            Left = 180, ;
            Height = 17, ;
            Width = 60, ;
            Alignment = 0, ;
            Caption = "Check1", ;
            ControlSource = "temp.check2", ;
            Name = "Check2"


      PROCEDURE Load
            CREATE TABLE temp ( fld c(10), check1 l, check2 l)
            FOR i=1 TO 1000
                  INSERT INTO temp VALUES (SYS(2015), RAND()>0.75, RAND()>.75)
            ENDFOR
            GO TOP IN temp
      ENDPROC


      PROCEDURE grid1.AfterRowColChange
            LPARAMETERS nColIndex
            IF this.RowColChange= 1 OR this.RowColChange= 3
                  thisform.container1.Refresh
            ENDIF
      ENDPROC


ENDDEFINE
0
 
LVL 2

Expert Comment

by:PeterGillett
Comment Utility
To do this from the Form editor:

Q1.

Set the HighlightStyle property of the grid to 2.

Q2.

Set the ControlSource property of the CheckBoxes to eg. mytable.checkbox1

To make them update on row selection - In the AfterRowColChange method.

ThisForm.CheckBox1.Refresh
ThisForm.CheckBox2.Refresh etc.

If the grid displays the checkbox in on of the columns, to make it update when you click a checkbox, in the Valid method of the CheckBoxes

ThisForm.Grid.Refresh

The AllowCellSelection of the grid will make it a non-editing, highlight only grid.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Assisted Solution

by:PeterGillett
PeterGillett earned 100 total points
Comment Utility
Q1

If you want to change the colour, it's the HighlightBackColor and HighlightForeColor properties of the grid.
0
 
LVL 35

Author Comment

by:Nick Sui
Comment Utility
I'm getting "Syntax Error" at

      ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
            Caption = "Header1", ;
            Name = "Header1"
0
 
LVL 14

Accepted Solution

by:
tusharkanvinde earned 400 total points
Comment Utility
Try with this

PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form


      Top = -1
      Left = 1
      Height = 562
      Width = 997
      DoCreate = .T.
      Caption = "My VFP Form"
      Name = "Form1"


      ADD OBJECT grid1 AS grid WITH ;
            ColumnCount = 3, ;
            Height = 361, ;
            Left = 84, ;
            RecordSource = "temp", ;
            Top = 60, ;
            Width = 733, ;
            Name = "Grid1", ;
            Column1.ControlSource = "temp.fld", ;
            Column1.Name = "Column1", ;
            Column2.ControlSource = "temp.check1", ;
            Column2.Name = "Column2", ;
            Column3.ControlSource = "temp.check2", ;
            Column3.Name = "Column3"




      ADD OBJECT container1 AS container1 WITH ;
            Top = 432, ;
            Left = 132, ;
            Width = 325, ;
            Height = 61, ;
            Name = "Container1"




      PROCEDURE Load
            CREATE TABLE temp ( fld c(10), check1 l, check2 l)
            FOR i=1 TO 1000
                  INSERT INTO temp VALUES (SYS(2015), RAND()>0.75, RAND()>.75)
            ENDFOR
            GO TOP IN temp
      ENDPROC


      PROCEDURE grid1.AfterRowColChange
            LPARAMETERS nColIndex
            IF this.RowColChange= 1 OR this.RowColChange= 3
                  thisform.container1.Refresh
            ENDIF
      ENDPROC


ENDDEFINE

DEFINE CLASS container1 as Container

      ADD OBJECT check1 AS checkbox WITH ;
            Top = 12, ;
            Left = 84, ;
            Height = 17, ;
            Width = 60, ;
            Alignment = 0, ;
            Caption = "Check1", ;
            ControlSource = "temp.check1", ;
            Name = "Check1"


      ADD OBJECT check2 AS checkbox WITH ;
            Top = 12, ;
            Left = 180, ;
            Height = 17, ;
            Width = 60, ;
            Alignment = 0, ;
            Caption = "Check1", ;
            ControlSource = "temp.check2", ;
            Name = "Check2"
ENDDEFINE
0
 
LVL 14

Expert Comment

by:tusharkanvinde
Comment Utility
Also make HighlightStyle = 1 or 2 as Peter Gillett has mentioned.

Change

      ADD OBJECT grid1 AS grid WITH ;
            ColumnCount = 3, ;
            Height = 361, ;
            Left = 84, ;
            RecordSource = "temp", ;
            Top = 60, ;
            Width = 733, ;
            Name = "Grid1", ;
            Column1.ControlSource = "temp.fld", ;
            Column1.Name = "Column1", ;
            Column2.ControlSource = "temp.check1", ;
            Column2.Name = "Column2", ;
            Column3.ControlSource = "temp.check2", ;
            Column3.Name = "Column

to

      ADD OBJECT grid1 AS grid WITH ;
            ColumnCount = 3, ;
            Height = 361, ;
            Left = 84, ;
            RecordSource = "temp", ;
            Top = 60, ;
            Width = 733, ;
            Name = "Grid1", ;
            Column1.ControlSource = "temp.fld", ;
            Column1.Name = "Column1", ;
            Column2.ControlSource = "temp.check1", ;
            Column2.Name = "Column2", ;
            Column3.ControlSource = "temp.check2", ;
            Column3.Name = "Column3", ;
            HighlightRow=.T., ;
            HighlightStyle=1
0
 
LVL 35

Author Closing Comment

by:Nick Sui
Comment Utility
Thanks Guys!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now