Data Grid
Data Grid
Data Grid
Data Grid
Data Grid
Data Grid Data Grid Data Grid Data Grid Data Grid Data Grid Data Grid Data Grid
Data Grid Data Grid
Data Grid
Go Back  Xtreme Visual Basic Talk > > > Data Grid


Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2004, 10:24 AM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default Data Grid Focus


How do I put the selected item on a data grid in to a variable?

Last edited by ncozzolino; 01-09-2004 at 01:39 PM.
Reply With Quote
  #2  
Old 01-09-2004, 10:49 AM
00100b's Avatar
00100bData Grid 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

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:
Code:
SELECT Field1, Field2 FROM TableName WHERE <condition> ORDER BY Field1
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #3  
Old 01-09-2004, 11:00 AM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default

Quote:
Originally Posted by 00100b
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:
Code:
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?
Reply With Quote
  #4  
Old 01-09-2004, 11:06 AM
00100b's Avatar
00100bData Grid 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

See the AllowSizing and Width properties of the Column(s) object of the DataGrid control.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #5  
Old 01-09-2004, 11:29 AM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default

Quote:
Originally Posted by 00100b
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?
Reply With Quote
  #6  
Old 01-09-2004, 11:35 AM
00100b's Avatar
00100bData Grid 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

Let's see the code please.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #7  
Old 01-09-2004, 11:44 AM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default

Quote:
Originally Posted by 00100b
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
Reply With Quote
  #8  
Old 01-09-2004, 11:47 AM
00100b's Avatar
00100bData Grid 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

I don't see anything there that would be attempting to set the Column widths.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #9  
Old 01-09-2004, 11:55 AM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default

Quote:
Originally Posted by 00100b
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.
Reply With Quote
  #10  
Old 01-09-2004, 01:39 PM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default

Quote:
Originally Posted by ncozzolino
How do I put the selected item on a data grid in to a variable?




Any body?
Reply With Quote
  #11  
Old 01-09-2004, 01:50 PM
00100b's Avatar
00100bData Grid 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

Have you tried it programmatically?
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #12  
Old 01-09-2004, 01:52 PM
ncozzolino ncozzolino is offline
Regular
 
Join Date: Jan 2004
Posts: 60
Default

Quote:
Originally Posted by 00100b
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?
Reply With Quote
  #13  
Old 01-10-2004, 10:33 AM
Dennis DVR's Avatar
Dennis DVRData Grid Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,577
Default

Quote:
Originally Posted by ncozzolino
Quote:
Originally Posted by 00100b
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.
Code:
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
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
data grid column format amidala General 1 11-07-2003 01:10 AM
data grid vk123 Database and Reporting 2 07-31-2003 06:16 AM
Edit in data grid control patricksky Interface and Graphics 0 04-26-2003 10:56 PM
data grid problem clonefish Database and Reporting 1 09-13-2002 04:31 AM
Data Grid Problem dusteater Database and Reporting 1 12-09-2000 11:33 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Data Grid
Data Grid
Data Grid Data Grid
Data Grid
Data Grid
Data Grid Data Grid Data Grid Data Grid Data Grid Data Grid Data Grid
Data Grid
Data Grid
 
Data Grid
Data Grid
 
-->