Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 24th, 2005, 07:43 AM
Registered User
 
Join Date: Jun 2005
Location: Mount Clemens, MI, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VS 2005 Beta 2 - DataGridView multi-column combo

I wanted to create a multi-column combobox, so I decided to try to use another DataGridView as the dropdown.

I have this somewhat working... I have a few issues however and I need direction. (Keep in mind, I have only been doing VB.Net for a couple of months)

I created the Column, Cell, and EditingControl, and I inherited the combobox column, cell, and editingcontrol for each one, respectively. I simply pass the DataSource down to the EditingControl, create a datagridview, set the datasource, and then add it to the controls collection, and then show it. This works... I can see the data in the grid, the columns, etc. I have a few problems...

1. If I add the grid to the EditingControl controls collection, the grid is in that editcontrol, so it will only show up inside the editcontrol. This would be fine if it showed up in the dropdown list, but it doesn't, it only shows up in the cell area.

2. If I add the grid to the form's controls collection, it works, except if you click in the grid, the dropdown closes and the editingcontrol disappears and so does the grid (if you remove the grid in the dropdownclosed event).

3. The location of the grid is a problem... I can't seem to find a location property that will tell the grid where to pop up below the cell you are dropping down. Plus, if the grid is part of the Form, it will only show up in the form, if the parent grid is at the bottom of the form, the dropdown grid will probably not show part of it because it will go below where the form stops...

Any idea how to overcome these? Is there a way to get the drop down window and have the dropdown grid display in there instead? That would be the ideal solution. If the drop down is open and you change items, the current row of the drop down grid changes, so I am assuming since they are the same datasource, if you change it in the grid, the dropdown will change as well..

The code so far is below if you need to play with it:


Public Class DataGridViewDropGridColumn
    Inherits DataGridViewComboBoxColumn
    Dim DropGridCell As DataGridViewDropGridCell

    Public Overrides Function Clone() As Object
        Dim newObj As DataGridViewDropGridColumn = MyBase.Clone()
        Return newObj
    End Function

    Public Sub New()
        DropGridCell = New DataGridViewDropGridCell()
        MyBase.CellTemplate = DropGridCell
    End Sub
End Class

Public Class DataGridViewDropGridCell
    Inherits DataGridViewComboBoxCell

    Public Overrides Function Clone() As Object
        Dim newObj As DataGridViewDropGridCell = MyBase.Clone()
        Return newObj
    End Function

    Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
        ' Set the value of the editing control to the current cell value.
        MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
        Dim ctl As DataGridViewDropGridEditingControl = CType(DataGridView.EditingControl, DataGridViewDropGridEditingControl)
        ctl.GridView.DataSource = Me.DataSource
        ctl.Text = CType(Me.Value, String)
    End Sub

    Public Overrides ReadOnly Property EditType() As Type
        Get
            Return GetType(DataGridViewDropGridEditingControl)
        End Get
    End Property

    Public Overrides ReadOnly Property ValueType() As Type
        Get
            Return GetType(Decimal)
        End Get
    End Property
End Class

Public Class DataGridViewDropGridEditingControl
    Inherits DataGridViewTextBoxEditingControl
    Dim grid As DataGridView

    Property GridView() As DataGridView
        Get
            Return grid
        End Get
        Set(ByVal value As DataGridView)
            grid = value
        End Set
    End Property

    Private Sub DataGridViewDropGridEditingControl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

    End Sub

    Private Sub DataGridViewDropGridEditingControl_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) 'Handles Me.DropDown
        Dim iIndex As Integer
        Dim frmParent As Form

        frmParent = Me.EditingControlDataGridView.GetContainerControl( )
        grid.Left = Me.Parent.Left
        grid.Top = Me.Parent.Top
        frmParent.Controls.Add(grid)
        iIndex = frmParent.Controls.GetChildIndex(grid)
        frmParent.Controls(iIndex).BringToFront()
        grid.Show()
    End Sub

    Private Sub DataGridViewDropGridEditingControl_DropDownClosed( ByVal sender As Object, ByVal e As System.EventArgs) 'Handles Me.DropDownClosed
        Dim frmParent As Form
        frmParent = Me.EditingControlDataGridView.GetContainerControl( )
        grid.Hide()
        frmParent.Controls.Remove(grid)
    End Sub

    Public Sub New()
        grid.AutoGenerateColumns = True
    End Sub
End Class


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-column combo box in datagridview aad1 C# 0 June 5th, 2006 09:58 AM
Multi column combo lists c_olinrb Access 4 July 21st, 2005 09:21 AM
VS.NET 2005 beta 1 and SQL Server 2005 beta 3 bmains Visual Studio 2005 4 March 15th, 2005 02:07 PM
multi-column combo myth12345 VB How-To 1 January 3rd, 2005 04:29 PM
Multi-Column Combo Boxes twsinc Access 1 September 22nd, 2004 12:14 PM



All times are GMT -4. The time now is 11:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.