Solved

Grids

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 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