You are here:

Visual Basic/Check Box and Datagrid control in VB 6.0

Advertisement


Question

Sample
I am shankar and interlevel using VB 6.0, I need code for the following. I am using Ms access as database.

I placed 4 check boxes on the form and one datagrid control and one ADODC control. The database file contains 4 columns like TE_NO,PO_NO,PO_date,Group.  These 4 names were setted as caption names of the 4 check boxes and I connected the database to the datagrid successfully by the following code:
Set con = New ADODB.Connection
Dim strsql As String

 con.ConnectionString = _
 "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=master.mdb"
 con.Open
 Set rs = New ADODB.Recordset
strsql = "Select Sl,TE_No From tmaster"
  

With rs
  .ActiveConnection = con
  .CursorLocation = adUseClient
  .CursorType = adOpenStatic
  .LockType = adLockOptimistic
  .Open strsql

End With

If rs.BOF = True Or rs.EOF = True Then
      Exit Sub
      
End If

Set DataGrid1.DataSource = rs
      DataGrid1.Refresh

*********************MY DOUBT IS **********************
Can I have the specific data in the Datagrid view which I select through check box. example If I select only 2 checkboxes I have to get the data of only those 2 columns in the Datagrid  

Answer
the datagrid configures well only with ADODC.
add adodc and point it to the table
create a query with only checked fields and  use

the sample code:

Private Sub Command2_Click()
Adodc1.RecordSource = "select * from testable where rate >100"
'adodc1.RecordSource = "select * from testable order by Item"
'adodc1.recordSource="Select Field1,field2 from testable"
' to display selcted columns you can use

Adodc1.Refresh

'DataGrid1.Columns(2).Visible = False
'depending upon the checked values
End Sub

Ravindra

Expertise

visual basic application programming from design to access information, sql, engineering and commercial applications. access databases, excel.(VB6) basic questions in vb 2008. Optional: 1)a large number of people want me to do work which takes some time and effort. can do projects in vb 2008. Pl.note that i would like to be paid for such work. 2) if you want me to spend quality time and do special work, i expect to be paid a reasonable price for my time. 3) if you are pleased with my reply you could consider a good amount. 4) you can visit my website http://ravindra.coolpage.biz

Experience

programming since the past 15 years. have completed a large number of projects in Industrial applications, finance,accounts, correspondence. excel macros etc

Education/Credentials
engineering, management degrees.

Past/Present Clients
project work for a Norway company,USA company and a Canadian company completed. Freelance Project work and Teaching. helping programmers with their work
teaching vb

©2014 About.com. All rights reserved.