Solved

Grids

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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