Hi all , I need the Textbox to display data from the Datagrid according to the columns data i wanted .
Like Textbox1.Text = Datagrid Columns (1)
I need Codes Thanks.
Hi all , I need the Textbox to display data from the Datagrid according to the columns data i wanted .
Like Textbox1.Text = Datagrid Columns (1)
I need Codes Thanks.
There is an easier way....
You need to set your datagrid to a recordsource property. (set datagrid.datasource = rs)
You then select the record you need and add the data to the textbox.
Text1.Text = rs!YourDataFieldName
If you want to add the text when you click on a selected grid record, try the following -
Private WithEvents cnServer As ADODB.Connection
Private WithEvents rsServer As ADODB.Recordset
Private Sub Command1_Click()
Set rsServer = New ADODB.Recordset
rsServer.Open "SELECT * FROM MyTableInDatabase", cnServer, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rsServer
DataGrid1.Columns(0).Width = 1750
DataGrid1.Columns(1).Width = 1750
DataGrid1.Columns(2).Width = 3300
Text1.Text = DataGrid1.Columns(2).Text '*******THE CODE YOU REQUIRE********
DataGrid1.Columns(3).Width = 1750
DataGrid1.Columns(4).Width = 1750
DataGrid1.Columns(5).Width = 1750
DataGrid1.Columns(6).Width = 2400
DataGrid1.Columns(7).Width = 2000
DataGrid1.Columns(8).Width = 2500
DataGrid1.Columns(9).Width = 1650
End Sub
Private Sub Form_Load()
Set cnServer = New ADODB.Connection
cnServer.CursorLocation = adUseClient
cnServer.Open "provider = microsoft.jet.oledb.4.0;persist security info=false;data source = C:\MyDatabase.mdb"
End Sub
This might differ slightly from what you need but it will put you on the right track....
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.