• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

Binding Data to Grid

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
Nirmal Sharma
Asked:
Nirmal Sharma
  • 4
  • 3
  • 2
2 Solutions
 
tusharkanvindeCommented:
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
 
Nirmal SharmaSolution ArchitectAuthor Commented:
Can you please post a working example?

Thanks
SP
0
 
tusharkanvindeCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
PeterGillettCommented:
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
 
PeterGillettCommented:
Q1

If you want to change the colour, it's the HighlightBackColor and HighlightForeColor properties of the grid.
0
 
Nirmal SharmaSolution ArchitectAuthor Commented:
I'm getting "Syntax Error" at

      ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
            Caption = "Header1", ;
            Name = "Header1"
0
 
tusharkanvindeCommented:
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
 
tusharkanvindeCommented:
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
 
Nirmal SharmaSolution ArchitectAuthor Commented:
Thanks Guys!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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