Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

playing with dbgrid...

Posted on 1999-01-21
13
Medium Priority
?
283 Views
Last Modified: 2010-05-03
If I click one cell of DBGrid, how can I get that cells value?? What DBGrid's event I have to use and what properties? Could you give me an example.

Thanks in advance!
0
Comment
Question by:majala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1469837
You could get directly the value of the needed field in the linked datarecordset.

Otherwise :
Dim Col1, Col2 as Column
Set Col1 = DBGrid1.Columns(0)
Set Col2 = DBGrid1.Columns(1)
Col1.Caption = "Column 1"
Col2.Caption = "Column 2"


0
 

Author Comment

by:majala
ID: 1469838
User clicks dbgrid and I wanna get that lines first (Data1.Recordset(0)) cells value and put it to the statusbar.
I tryed to use recordset but recordset gave me always previous value. I mean that when I clicked the next line, recordset gave that previous lines first cells value.

I tryed this:
Private Sub DBGrid_Click()

  StatusBar1.Panels(3).Text = Data1.Recordset(0)

End Sub

0
 

Author Comment

by:majala
ID: 1469839
I ment that recordset gave that previous lines value that user had selected. If user has selected line 10 and after that selects line 21, recordset gives me that first cells value from line 10.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:waty
ID: 1469840
Did you tried StatusBar1.Panels(3).Text = DBGrid1.Columns(0)

0
 

Author Comment

by:majala
ID: 1469841
I tried now and I got an error:

  Run-time error '424':
  Object required


0
 
LVL 3

Expert Comment

by:sduckett
ID: 1469842
This should work:

MsgBox DBGrid1.Columns(DBGrid1.Col).Text
0
 

Author Comment

by:majala
ID: 1469843
Sorry, previous comment was wrong! I doublechecked my grids name!

Anyway it works in a same way as when I used recordset.
Should I use it with some other event than Click-event??
0
 

Author Comment

by:majala
ID: 1469844
scucketts answer worked same way as watys comment...
0
 

Author Comment

by:majala
ID: 1469845
when I click a cell first time that cells value turns blue but this (StatusBar1.Panels(3).Text = DBGrid.Columns(0)) don't give me a new value. But when I click second time that cell, I get that new value.
0
 
LVL 3

Accepted Solution

by:
sduckett earned 150 total points
ID: 1469846
The RowColChange event does it but you may want to disable it on first entry to the grid, so:


Dim Doit As Boolean

Private Sub DBGrid1_GotFocus()
Doit = False
End Sub


Private Sub DBGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Doit = True
End Sub

Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
If Doit Then
MsgBox DBGrid1.Columns(DBGrid1.Col).Text
End If
End Sub

0
 

Author Comment

by:majala
ID: 1469847
It seem to work fine but it won't work in a first entry even if I tried just like you said?!
0
 
LVL 3

Expert Comment

by:sduckett
ID: 1469848
waty's answer is effectively the same as mine (fortunately TEXT appears to be the default property for COLUMNS) but only returns the data in the first column whichever column you click.
0
 
LVL 3

Expert Comment

by:sduckett
ID: 1469849
What I meant by 'on first entry' is that the event used is triggered if you tab to the grid, not just if you click a field.
There are other times that thwe event is triggered such as going to the next record using the data control so it is useful to have some means of disabling the event.
This sort of behaviour is easily seen if using message boxes as I have, but if your just setting a variable to be the value returned then it probably doesn't matter.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question