Data Grid

ncozzolino
01-09-2004, 11:24 AM
How do I put the selected item on a data grid in to a variable?

00100b
01-09-2004, 11:49 AM
If you only want the DataGrid to be populated with two columns from a table, then specify those two field names in the SELECT statement versus using the * symbol (which says that you want all fields).

If you want to sort the data in a specific order, then use the ORDER BY statement in the query.

For example:

SELECT Field1, Field2 FROM TableName WHERE <condition> ORDER BY Field1

ncozzolino
01-09-2004, 12:00 PM
If you only want the DataGrid to be populated with two columns from a table, then specify those two field names in the SELECT statement versus using the * symbol (which says that you want all fields).

If you want to sort the data in a specific order, then use the ORDER BY statement in the query.

For example:

SELECT Field1, Field2 FROM TableName WHERE <condition> ORDER BY Field1


Great thanks!! Ok, how do I resize the data grid fields for the text from the database?

00100b
01-09-2004, 12:06 PM
See the AllowSizing and Width properties of the Column(s) object of the DataGrid control.

ncozzolino
01-09-2004, 12:29 PM
See the AllowSizing and Width properties of the Column(s) object of the DataGrid control.

The allowsizing option was checked and as soon a I changed the Width setting my data grid came up empty with 4 columns instead of two. Any ideas?

00100b
01-09-2004, 12:35 PM
Let's see the code please.

ncozzolino
01-09-2004, 12:44 PM
Let's see the code please.

From Form1.frm
Private Sub Exit_Click()
End
End Sub

Private Sub Form_Load()
Call OpenAccessDataBase
Call OpenAccessRecordSet("SELECT Cltnum, Cltname FROM Clients ORDER BY Cltnum")
Call FillDBGridWithData

End Sub
Sub FillDBGridWithData()

DataGrid1.Caption = Cap5
DataGrid1.Columns.Add (0)
Set DataGrid1.DataSource = rstObj
End Sub


From Module1

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public cnxnObj As Object
Public rstObj As Object
Public Sub OpenAccessDataBase()
Dim AccessConnect As String
Dim strFileName As String
Dim strFilePath As String

strFileName = "I:\VPMDATA\2003Backup\DRCPA\dorfmanrobbie.mdb"
strFilePath = App.Path
Set cnxnObj = CreateObject("ADODB.Connection")
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & strFileName & ";" & _
"DefaultDir=" & strFilePath & ";" & _
"Uid=Admin;Pwd=;"
cnxnObj.Open AccessConnect

End Sub
Public Sub OpenAccessRecordSet(strSQL As String)
Set rstObj = CreateObject("ADODB.Recordset")
rstObj.Open strSQL, cnxnObj, 1, 1, 1
End Sub

00100b
01-09-2004, 12:47 PM
I don't see anything there that would be attempting to set the Column widths.

ncozzolino
01-09-2004, 12:55 PM
I don't see anything there that would be attempting to set the Column widths.

I went to my form then right clicked on the data grid then selected properties. I changed the column width in there. I did not realize I could do it programmically.

ncozzolino
01-09-2004, 02:39 PM
How do I put the selected item on a data grid in to a variable?


Any body?

00100b
01-09-2004, 02:50 PM
Have you tried it programmatically?

ncozzolino
01-09-2004, 02:52 PM
Have you tried it programmatically?

Not yet but I looked at it and put it on the back burner for now. My main issue is how do I put a selected item from a data grid in to a variable?

Dennis DVR
01-10-2004, 11:33 AM
Have you tried it programmatically?

Not yet but I looked at it and put it on the back burner for now. My main issue is how do I put a selected item from a data grid in to a variable?

I know this also possible using the rs object
and i just would like to add the selbookmark is not sorted but it is how you select the record ib the record.

Private Sub Command1_Click()
Dim i As Long
Dim j As Long
Dim x() As String
ReDim x(DataGrid1.SelBookmarks.Count - 1) As String
For i = 0 To UBound(x)
Adodc1.Recordset.Move DataGrid1.SelBookmarks(i) - 1, 1
For j = 0 To Adodc1.Recordset.Fields.Count - 1
x(i) = x(i) + CStr(Adodc1.Recordset.Fields(j)) + " "
Next
x(i) = Right(x(i), Len(x(i)) - 1)
MsgBox x(i)
Next
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum