Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Binding Data to Grid

Posted on 2010-08-24
9
Medium Priority
?
441 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
Industry Leaders: 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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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