Advertisement

12.10.2004 at 02:56AM PST, ID: 21237693
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

DataGrid and ComboBox
Tags: datagrid, combobox
Hi, please I would like some help in a little problem ... I have a datagrid binded to a dataset, and there are fields in this grid that are foreign keys from other tables, so I would like to be able to choose between these values by using a comboBox in the datagrid .. How can I do it ? I just want the comboBox to appear when the user clicks on the given dataGridTextBox column .. and thanks for anyone who helps.
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: zahir79b
Solution Provided By: iboutchkine
Participating Experts: 7
Solution Grade: B
Views: 469
Translate:
Loading Advertisement...
12.10.2004 at 03:31AM PST, ID: 12791283

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.10.2004 at 05:23AM PST, ID: 12791918

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.10.2004 at 09:24AM PST, ID: 12794365

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.31.2004 at 10:21AM PST, ID: 12933516

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2005 at 11:28AM PDT, ID: 13938638

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.11.2005 at 01:57PM PDT, ID: 13981873

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
08.01.2005 at 01:12PM PDT, ID: 14573510

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.12.2005 at 09:12AM PDT, ID: 14865096

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.12.2005 at 11:12AM PDT, ID: 14866048

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
12.10.2004 at 03:31AM PST, ID: 12791283

Rank: Sage

You'll need to create your own DataGridComboBoxColumn Style class and use it for formatting the grid

Here are some links that might help you (there are some working codes)
(http://www.gotdotnet.com/userfiles/Boongieman/DropDownColumn.zip)

http://www.codeproject.com/cs/miscctrl/datagridcomboboxcolumn.asp

 
12.10.2004 at 05:23AM PST, ID: 12791918

Rank: Sage

Imports System.Data.OleDb
Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Public MyCombo As New ComboBox()

    Dim sDBNAme As String = "c:\TestDB\Northwind.mdb"
    Dim sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBNAme & ";Persist Security Info=False"
    Dim con As New OleDbConnection(sConn)
    Dim daEmp As New OleDbDataAdapter("Select * From Employees", con)

    Public ds As New DataSet()


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler MyCombo.TextChanged, AddressOf Ctrls_TextChanged
        'Fill ComboBox list.
        MyCombo.Name = "MyCombo"
        MyCombo.Visible = False
        MyCombo.Items.Clear()
        MyCombo.Items.Add("Sales Representative")
        MyCombo.Items.Add("Inside Sales Coordinator")
        MyCombo.Items.Add("Vice President, Sales")
        MyCombo.Items.Add("Sales Manager")
        MyCombo.Items.Add("Flunky")

        daEmp.Fill(ds, "Employees")

        'Set the RowHeight of the DataGrid to the height of the ComboBox.
        DataGrid1.PreferredRowHeight = MyCombo.Height

        DataGrid1.DataSource = ds

        DataGrid1.DataMember = "Employees"
        'Add ComboBox to the Control collection of the DataGrid.
        DataGrid1.Controls.Add(MyCombo)
    End Sub
    Private Sub DataGrid1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
        If DataGrid1.CurrentCell.ColumnNumber = 3 Then
            MyCombo.Width = DataGrid1.GetCurrentCellBounds.Width
        End If
    End Sub

    Private Sub Ctrls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If DataGrid1.CurrentCell.ColumnNumber = 3 Then
            MyCombo.Visible = False
            If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
                SendKeys.Send("*")
            End If
            DataGrid1.Item(DataGrid1.CurrentCell) = MyCombo.Text
        End If
    End Sub

    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        If DataGrid1.CurrentCell.ColumnNumber = 3 Then
            MyCombo.Visible = False
            MyCombo.Width = 0
            MyCombo.Left = DataGrid1.GetCurrentCellBounds.Left
            MyCombo.Top = DataGrid1.GetCurrentCellBounds.Top
            MyCombo.Text = DataGrid1.Item(DataGrid1.CurrentCell) & ""
            MyCombo.Visible = True
        Else
            MyCombo.Visible = False
            MyCombo.Width = 0
        End If
    End Sub

    Private Sub DataGrid1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Scroll
        MyCombo.Visible = False
        MyCombo.Width = 0
    End Sub

    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
        MyCombo.Visible = False
        MyCombo.Width = 0
    End Sub

End Class

Accepted Solution
 
12.10.2004 at 09:24AM PST, ID: 12794365
About the 2nd link in Arif eqbal's answer, I didnt find a DataGridComboBoxColumn class in VB.Net .. there are only DataGridTextBoxColumn and DataGridBoolColumn .. is it right?
 
12.31.2004 at 10:21AM PST, ID: 12933516
In the 2nd link that arif_eqbal posted, you're supposed to download the .zip at the top of the article which includes the source for the DataGridComboBoxColumn class, which overrides the normal columnstyle class and replaces the default textbox with a combobox.
 
05.05.2005 at 11:28AM PDT, ID: 13938638
I had my company purchase 2 licenses for this productL: http://www.rustemsoft.com/dgc.htm

It has more than just your combo box, but I have found that I use several of the built in options now that they are available.  The amount of time it would have taken me to code these was worth the price they charged.  Just my $0.02
 
05.11.2005 at 01:57PM PDT, ID: 13981873
I am using Rustemsoft as well and it is a great datagrid enhancement.  However, they still have not responded to my question regarding how to set all columns to NOT Selected (-1) when adding a new row. Right now, it intermittently shows the first row of the dropdown box when I add a new row.
 
08.01.2005 at 01:12PM PDT, ID: 14573510
I have a question as to what part of the code is doing above:

If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
   SendKeys.Send("*")
End If


Is the above saying that if the user doesn't select anything from the combobox that a * will be placed in the underlying cell?

Thanks
 
09.12.2005 at 09:12AM PDT, ID: 14865096
The original question posed by zahir79b, it seems was asking about handling foreign key to make it look readable to the user by using a combo box in thte data grid.

The solution posed by iboutchkine doesn't really solve the foreign key issue.

I modified code in the solution by iboutchkine to handle the foreign key / human readable combo scenario.

STEP 1) First, assume that your Employees table was related to a Roles table in the database.  The Employees table contains the foreign key to the Roles table.  In code the roles are defined such as this:

      Public Enum Roles
            Sales = 1
            Estimator = 2
            Engineer = 4
            Purchasor = 8
            Inventory = 16
            Accountant = 32
            Management = 128
            Executive = 256
            ExecutiveManagement = 384             'Executive Or Management
            SysOp = 512
      End Enum


STEP 2)  In the Private Sub Form1_Load event, set the Combo Items to the Roles enumeration directly, as follows.

Dim r As Roles

            MyCombo.Items.Add(r.Sales)
            MyCombo.Items.Add(r.Estimator)
            MyCombo.Items.Add(r.SalesEstimator)
            MyCombo.Items.Add(r.Engineer)
            MyCombo.Items.Add(r.Purchasor)
            MyCombo.Items.Add(r.Inventory)
            MyCombo.Items.Add(r.Accountant)
            MyCombo.Items.Add(r.ProjectManager)
            MyCombo.Items.Add(r.Management)
            MyCombo.Items.Add(r.SalesManagement)
            MyCombo.Items.Add(r.EngineerManagement)
            MyCombo.Items.Add(r.PurchasingManagement)
            MyCombo.Items.Add(r.InventoryManagement)
            MyCombo.Items.Add(r.Executive)
            MyCombo.Items.Add(r.ExecutiveManagement)
            MyCombo.Items.Add(r.ExecutiveSales)
            MyCombo.Items.Add(r.ExecutiveEngineering)
            MyCombo.Items.Add(r.ExecutivePurchasor)
            MyCombo.Items.Add(r.ExecutiveAll)
            MyCombo.Items.Add(r.SysOp)

STEP 3) In the Ctrls_TextChanged event, set the selected combo Roles value to the datagrid cell, as follows:

DataGrid1.Item(DataGrid1.CurrentCell) = CType(MyCombo.SelectedItem, Roles)


===
In this manner, the enumeration provides a human-readable combobox, while the datagrid is satisfied with using the enumeration's value, which corresponds to the foreign key relation. Hope this helps.

Nick

P.S.  Regarding vsshah question:  He's sending a keystroke if the datagrid cell is null or a blank string, but I'm not sure why.
 
09.12.2005 at 11:12AM PDT, ID: 14866048
Per my previous Post, I add another Step:

STEP 4) In DataGrid1_CurrentCellChanged event, set the Combo box to the current datagrid cell value, as follows:

MyCombo.SelectedItem = CType(DataGrid1.Item(DataGrid1.CurrentCell), Roles)

Best,

Nick
 
 
20080236-EE-VQP-29