Solved

Grids

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now