Solved

msflexgrid format

Posted on 2002-05-21
6
914 Views
Last Modified: 2008-02-01
here is my code..........

If Text1.Text <> "" Then
Dim search As String
Dim myconn
search = Text1.Text
search = Trim$(search)
Set myconn2 = New ADODB.Connection
myconn2.Open "Provider=Microsoft.JET.OLEDB.4.0;Persist Security Info=False;Data Source=c:\farebase\farebase.mdb"
Set myado2 = myconn2.Execute("SELECT farebase.from_1, farebase.to_1 From farebase where farebase.from_1 like '%" & search & "%'order by farebase.from_1 desc;")
Num = 0 + 0
 While Not myado2.EOF
    Num = Num + 1
    myado2.MoveNext
  Wend
End If
MsgBox Num

MSFlexGrid1.Cols = Num + 1
MSFlexGrid1.Rows = Num + 1

how do i set the headers of the columns???

i use this method to add into the cells...........

MSFlexGrid1.TextMatrix(1, 1) = "Hello EE"
MSFlexGrid1.TextMatrix(1, 2) = "Hello EE again"

what is the best way of putting data in, in this format..........


msflexgrid1 col1="text1" , col2="text2" etc etc

in one line, (it is easier for me to understand.

Also when somebosy clicks one specific row, i want the data in a hidden field to be usable..........


(ref ,  col1,   col2,   col3,   etc)
2   ,  name,  address,  tel,    fax
3   ,  fred,  123 road, 3456,   33333

the ref is hodden to the punter, but if they click the row it will bring up a msgbox with the ref num in...

I hope this makes sense, if it does not tell me.

Gavin (AKA Bolox)
0
Comment
Question by:bolox
[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
  • 4
  • 2
6 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7023534
The headers are row zero so you can use:

MSFlexgrid1.TextMatrix(0,1) = "Column One"
MSFlexgrid1.TextMatrix(0,2) = "Column Two"

Use the Click event:

Private Sub MSFlexgrid1_Click()
  Msgbox MSFlexgrid1.TextMatrix(MSFlexgrid1.MouseRow,0)
End Sub

This bit I don't understand, can you clarify?

>> what is the best way of putting data in, in this format..........


msflexgrid1 col1="text1" , col2="text2" etc etc

in one line, (it is easier for me to understand.
0
 
LVL 1

Author Comment

by:bolox
ID: 7023565
actually i do not understand the last bit myself..........so i will not need that after all


the points are your already, for 10 extra points, how can i have the columns autosize to the contents.

for example, in one of my columns the results will always be one char in size and others are only 2 chars, where as the rest may need 20 chars???

if this is not easy, i will up the points

thanx

B

0
 
LVL 43

Accepted Solution

by:
TimCottee earned 150 total points
ID: 7023600
Well you are right it is not that easy but equally not impossible. This snippet will autosize every column of the flexgrid, you just need to adjust the for..next loop to handle the appropriate columns:

Private Sub Command2_Click()
   Dim aryWidths() As Double
   ReDim aryWidths(MSFlexGrid1.Cols - 1)
   For intRow = 1 To MSFlexGrid1.Rows - 1
       For intCol = 0 To MSFlexGrid1.Cols - 1
           If Form1.TextWidth(MSFlexGrid1.TextMatrix(intRow, intCol)) > aryWidths(intCol) Then
               aryWidths(intCol) = Form1.TextWidth(MSFlexGrid1.TextMatrix(intRow, intCol))
           End If
       Next
   Next
   For intCol = 0 To MSFlexGrid1.Cols - 1
       MSFlexGrid1.ColWidth(intCol) = aryWidths(intCol) + 100
   Next
End Sub
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 1

Author Comment

by:bolox
ID: 7023609
you are a star
0
 
LVL 1

Author Comment

by:bolox
ID: 7023611
well deserved points,

speak to ya soon

Gavin
0
 
LVL 1

Author Comment

by:bolox
ID: 7023651
how could i preset the columns to a certain size, knowing there are 5 cols for example,

so, col1 is X big
    col2 is Y  big
   etc
0

Featured Post

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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

752 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