Results 1 to 4 of 4

Thread: Add ComboBox in DataGrid in VB 6.0

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Add ComboBox in DataGrid in VB 6.0

    Hello Friends,

    I am developing new project by using VB 6.0.
    I want that particular column of Datagrid control should contain a Combobox in it. so that user can select the value from given list.

    But i am not able to do it.
    Please help me.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Add ComboBox in DataGrid in VB 6.0

    You can't put a combobox directly into the datagrid control.

    I have made this kind of myself with mshflexgrid control.

    With msHFlexGrid1
    Combo1.Move .CellLeft, .CellTop, .CellWidth
    End Sub

    This doesn't look nice but it can be done without buying third party
    controls.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Add ComboBox in DataGrid in VB 6.0

    Just follow the given steps:

    Step1:

    Place a combo box any where in the form and populate the values as you need. Set the visible property to false in design time itself.

    Step2:

    Now we can set the combo box on any cell of the selected column, let’s say on column 7.

    The fallowing code shlould write in the row column change event of the data grid



    Here cmbGridDisposition is the name of the requred combo box.


    Code:
    If rptGrid.Col = 7 Then
    
            cmbGridDisposition.Visible = True
    
            cmbGridDisposition.Top = rptGrid.Columns(7).Top
    
            rptGrid.RowHeight = cmbGridDisposition.Height
    
    cmbGridDisposition.Top = rptGrid.Columns(7).Top + rptGrid.Top + rptGrid.RowTop(rptGrid.Row)
    
            cmbGridDisposition.Top = cmbGridDisposition.Top - 200
    
            cmbGridDisposition.Width = rptGrid.Columns(7).Width
    
           
    
            cmbGridDisposition.Left = rptGrid.Columns(7).Left + rptGrid.Left
    
           
    
            If Len(rptGrid.Columns(7).Text) > 0 Then
    
                cmbGridDisposition = rptGrid.Columns(7).Text
    
            End If
    
        Else
    
            cmbGridDisposition.Visible = False
    
        End If
    This will work only if the cell value matched with the list of combo box values.

    Step3:

    To affect the selected value from the drop down over the grid cell. We should write code under the

    Click event of the combo box.

    Code:
        If cmbGridDisposition.Visible = True Then
    
            rptGrid.Columns(7).Text = cmbGridDisposition.Text
    
        End If

    By running the code you can able to select value for a particular column from the drop down list.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Add ComboBox in DataGrid in VB 6.0

    Hope this code will help you...
    Code:
    Private Sub datagrid1_Click() 
    
             ' Position and size the ComboBox, then show it. 
              Combo1.Top = DataGrid1.Columns(2).Top 
              Combo1.Width = DataGrid1.Columns(2).Width 
              Combo1.Left = DataGrid1.Columns(2).Left + DataGrid1.Left 
              Combo1.Top = DataGrid1.Columns(2).Top + DataGrid1.Top 
              Combo1.Text = DataGrid1.Columns(2).Text 
              Combo1.Visible = True 
    End Sub 
    
    
    Private Sub Combo1_Click() 
              ' Place the selected item into the columns(1). and hide the ComboBox. 
              DataGrid1.Columns(2).Text = Combo1.Text 
              Combo1.Visible = False 
    End Sub

Similar Threads

  1. Need Help With ComboBox
    By Reyas in forum Software Development
    Replies: 1
    Last Post: 29-04-2012, 12:53 PM
  2. Use of combobox in script
    By Martien in forum Software Development
    Replies: 3
    Last Post: 15-01-2010, 11:58 AM
  3. Combobox and Text value
    By HarshaB in forum Software Development
    Replies: 5
    Last Post: 09-11-2009, 07:16 PM
  4. How to lock combobox
    By JamesB in forum Software Development
    Replies: 3
    Last Post: 19-03-2009, 07:20 PM
  5. How to add file content to combobox
    By MikeY007 in forum Software Development
    Replies: 3
    Last Post: 11-10-2008, 03:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,584,474.37137 seconds with 17 queries