Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use the button function of a cell in datagrid control 7

Status
Not open for further replies.

nightcaptor

Programmer
Jul 30, 2002
2
SG
Hi,

I'm currently developing a stand-alone program that needs to use the datagrid control in VB. I need to have dropdown list from the cells in the datagrid but I do not know how to do so. I had searched the web but can only find solution for web-based applications. Can anyone help me? I need to solve this problem urgently.

Thank you
 
1. Add the button (Note: iColIndex is the index of the column that you want the button for)

grdDataGrid.Columns(iColIndex).Button = True

2. Add a listbox to the form and set its' visible property to False. I'll call it List1 here.

3. In the grdDataGrid_ButtonClick event add the items to the list box, position it and then make it visible:

With List1
.Clear

Select Case ColIndex
Case 1 '(or the correct column index)
.AddItem "Item#1"
.ItemData(.NewIndex) = 1
End Select

.Left = grdDataGrid.Columns(ColIndex).Left
.Width = grdDataGrid.Columns(ColIndex).Width

.Top = grdDataGrid.Top + DBGrid1.RowTop(grdDataGrid.Row) + grdDataGrid.RowHeight
.Visible = True
.SetFocus
End With


4. In the List1 Click event:
grdDataGrid.Columns(grdDataGrid.col).Value =List1.ItemData(List1.ListIndex)

5. And in the List1 LostFocus event:

List1.Visible = False
grdDataGrid.SetFocus

6. The rest of the functionality I will leave up to you.....
 
Someone else pointed me to this... Great post and very helpful! Thanks CClint!
 
CCLINT,

I have been looking for a useful functality for the DataGrid_ButtonClick event for awhile now. I think this will be an valuable reference.

Thank you...Tek-Tips RULES!!!!!
 

I am happy to have been of help! [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
This sounds just like something I need, but could you explain a little further? I'm not clear on the function of the list box.

Kathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top