Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid question

Status
Not open for further replies.

LLudlow

Programmer
Oct 5, 2001
186
0
0
CA
I have put a datagrid on my form. When i press the command button i want to fill the grid with the data from a table in my database. for examble: "SELECT * FROM tblTest" .I am using vb6.0 and SQL Server 7.0. I already have a connection to SQL server for my other forms so i will use this as my connection string but my question is how do i fill the columns in the datagrid with code, not throught adoc?

Thanks
Lludlow
 
Select the form and then the datagrid in design.
Right click the datagrid, select the properties.
Select the Columns tab.
In this display you will find a list box containing the column array beginning with 0.
Select this column and asign a title by typing ColumnTitle in the Caption field.
Asign the datafield by selecting the datafield from the list.

You will find excellent programming exercises if you purchase the book, "Advanced Programming using Visula Basic"
by Julia Case Bradley and Anita C. Millspaugh
 
This will only work if i have an ADOC control on the form. Is there a way i can this without this control?

I have tried calling a function from another class. Here is the code:

Set DataGrid1.DataSource = mobjTest.GetAllTest

The GetAllTest function retrieves all of the data from the Test table in my database. So what i want to do is to take the data from this function and display it on the datagrid.

But i am getting an Object Required Error?

 
You might want to use a flex grid.

It would go something lik this >

With rndVideo
For rowNumber = 1 To TotalRecords - 1
Get #1, rowNumber, rndVideo
Grid.Row = rowNumber
For colNumber = 1 To 6
Select Case colNumber
Case 1
Grid.Col = colNumber
Grid.Text = .RecordNumber
Case 2
Grid.Col = colNumber
Grid.Text = .MovieNumber
Case 3
Grid.Col = colNumber
Grid.Text = .StudioID
Case 4
Grid.Col = colNumber
Grid.Text = .Title
Case 5
Grid.Col = colNumber
Grid.Text = .Category
Case 6
Grid.Col = colNumber
Grid.Text = .Length
End Select
Next colNumber
Next rowNumber
End With
 
I am very new to grid controls. Is there an easy that i can use one grid control to display different info based upon which cmdbutton is clicked. For example if cmdbutton1 is clicked then the grid displays info from tblTest. If cmdbutton2 is clicked then info is displayed from tblTest2.
In other words I want to call different functions based upon what button the user clicks.

thanks

lludlow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top