Solved

Grids

Posted on 2002-07-16
5
398 Views
Last Modified: 2010-05-02
Hi,

Can anyone tell me if it is possible to have a column in a grid display a list box and also to have a column in a grid display the result of a formulae??
What grid if any is the best to use for this??
I will be connecting a Grid to a SQL statement but I want following columns to allow for user selection of data, hence the list box.

Thanks
0
Comment
Question by:SCOTT78
[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
  • 3
  • 2
5 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7157093
Well you have a range of choices really, any grid pretty much can be made to have the appearance of a listbox or combobox in the cell, though the standard grids with VB require a bit of sleight-of-hand to do this. A commercial grid product such as the TrueDBGrid or VSFlexgrid both available from http://www.componentone.com offer the ability to have a combo box applied to a column or cell. As for the result of a formula, this is usually achieved by calculating the appropriate result in a Grid_AfterEdit or Grid_LeaveCell event or equivalent, except for an excel compatible component such as the Farpoint spreadsheet grid this is not a feature of standard data bound grid controls.

I would personally recommend the VSFlexgrid, not free of course though you can download an evaluation version as I have been using it for a few years now and it seems quite capable of coping with pretty much anything I need to do with it.
0
 

Author Comment

by:SCOTT78
ID: 7157132
Thanks Tim.
Could you possibly let me know how I would make a column into a list box possibly using the FlexiGrid or perhaps the regular Grid?
Im very new to VB and dont have that much experience.

Thanks again your help is very much appreciated,
Scott
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 75 total points
ID: 7157167
For a standard DataGrid (or DBGrid).

This example uses a datacombo in the cell, however it works equally well with a combo or listbox or
textbox or checkbox etc.

You need to set the button property of the appropriate column to true:

Datagrid1.Columns(1).Button = True

And then use the following to make the datacombo appear in the cell when the button is clicked.

Private Sub DataGrid1_ButtonClick(ByVal ColIndex As Integer)
' Assign the Column object to Co because it will be used
' more than once.
Dim Co As Column
 
Set Co = DataGrid1.Columns(ColIndex)
 
' Position and drop down list1 at the right edge of the
' current cell.
DataCombo1.Left = DataGrid1.Left + Co.Left + Co.Width
DataCombo1.Top = DataGrid1.Top + DataGrid1.RowTop(DataGrid1.Row)
DataCombo1.Visible = True
DataCombo1.ZOrder 0
DataCombo1.SetFocus
End Sub

Private Sub DataGrid1_Scroll(Cancel As Integer)
' Hide the list if we scroll.
DataCombo1.Visible = False
End Sub

Private Sub List1_Click()
'Update the appropriate field in the record.
DataCombo1.Visible = False
End Sub

When the button is clicked, the data combo is displayed next to the field. Choosing an item
from the list will then update the record (you need to put in the appropriate code for this) and hide the datacombo.
0
 

Author Comment

by:SCOTT78
ID: 7161738
Thanks Tim.

I need to carry out my work using a MSFlexGrid control.
Could you let me know if this is possible in this control and how to carry it out.

Thanks Again
Scott
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7161742
Have a look here, it describes various methods for simulating in-cell editing with a flexgrid. Essentially the theory is the same as for the datagrid but the properties/methods are slightly different.

http://support.microsoft.com/default.aspx?scid=kb;EN-GB;q241355
0

Featured Post

Technology Partners: 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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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