Solved

Binding Data to Grid

Posted on 2010-08-24
9
395 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:Nirmal Sharma
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 33508458
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:Nirmal Sharma
ID: 33509102
Can you please post a working example?

Thanks
SP
0
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 33509299
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
ID: 33509587
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 2

Assisted Solution

by:PeterGillett
PeterGillett earned 100 total points
ID: 33509599
Q1

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

Author Comment

by:Nirmal Sharma
ID: 33509760
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
ID: 33509814
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
ID: 33509858
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:Nirmal Sharma
ID: 33511426
Thanks Guys!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

25 Experts available now in Live!

Get 1:1 Help Now