Solved

Grids

Posted on 2002-07-16
5
391 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

821 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