Results 1 to 3 of 3

Thread: [RESOLVED] Data-bound combo box in DataGridView

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    18

    Resolved [RESOLVED] Data-bound combo box in DataGridView

    I have a datagridview bound to one SQL data table. Within that datagridview, I have one cell, Hotel, which is set up as a combo box which has a hotel table as it's datasource. The properties are shown below. My problem: When the user goes to the hotel combobox in the datagrid, if they begin to type in a hotel, even though the autocomplete property is set to false, the combobox does just that. Which will not allow my user to enter a new hotel name - one not in the list that they would then want to add. Any ideas on how I can get the combo box to only suggest hotels (like you could in a normal combo box) or even to not even do that, so that a user could potentially type in a new hotel?
    Properties for Hotel column in bound datagridview:
    Autocomplete: False
    ReadOnly: False
    DataPropertyName: Hotel
    Datasource: HotelsBindingSource
    DisplayMember: HotelScreenName
    ValueMember: HotelID
    ColumnType: DataGridViewComboBoxColumn

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data-bound combo box in DataGridView

    A standard ComboBox has a DropDownStyle property that you can set to DropDown or DropDownList. One allows the user to enter any value and the other requires them to select from the list. A ComboBox in a DataGridView acts like a standard ComboBox with its DropDownStyle set to DropDownList, i.e. it requires that the user make a selection from the list. That's because it's the SelectedValue of the ComboBox that corresponds to the Value of the cell. If the user could enter any old value then there would be no corresponding entry in the ValueMember column so the cel couldn't have a value. That situation makes no sense so it is prohibited. You can create your own column types or customise the existing ones if you want something different but it is not for the faint-hearted.
    Last edited by jmcilhinney; Jun 12th, 2006 at 11:56 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    18

    Resolved Re: Data-bound combo box in DataGridView

    Thank you for the great explanation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width