?
Solved

Binding Data to Grid

Posted on 2010-08-24
9
Medium Priority
?
435 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
[X]
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
  • 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
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
 
LVL 2

Assisted Solution

by:PeterGillett
PeterGillett earned 400 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 1600 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

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