Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. DataGridView and Combo Boxes (my brain hurts)

DataGridView and Combo Boxes (my brain hurts)

Scheduled Pinned Locked Moved Windows Forms
questioncsharpcssasp-netdatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davebarkshire
    wrote on last edited by
    #1

    I mostly use ASP.net but have spent the day wrestling with a date view grid. I have a column which has a dropdown so when I populate the grid I programatically add a combo (DataGridViewComboBoxCell) to the row and can populate the items with data. The column is a normal DataViewGridTextBoxColumn because I want to have a completely free hand in what I put in the cells in this column. But... the dropdowns have a blank entry at the top which I'd like to get rid of and also there is no property to select an item in the dropdown such as selectedIndex. How han I get rid of the space at the top (blank entry) and how can I set the selected index property? Also, when I want to read the value from the combo and have a reference to the DataGridViewComboBoxCell object in that cell, how do I read the selected value from the combo?

    B 1 Reply Last reply
    0
    • D davebarkshire

      I mostly use ASP.net but have spent the day wrestling with a date view grid. I have a column which has a dropdown so when I populate the grid I programatically add a combo (DataGridViewComboBoxCell) to the row and can populate the items with data. The column is a normal DataViewGridTextBoxColumn because I want to have a completely free hand in what I put in the cells in this column. But... the dropdowns have a blank entry at the top which I'd like to get rid of and also there is no property to select an item in the dropdown such as selectedIndex. How han I get rid of the space at the top (blank entry) and how can I set the selected index property? Also, when I want to read the value from the combo and have a reference to the DataGridViewComboBoxCell object in that cell, how do I read the selected value from the combo?

      B Offline
      B Offline
      bigbrownbeaver
      wrote on last edited by
      #2

      From MSDN: "Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property." I am not sure what will happen when you set the value, although I will assume that it will change the selection. You can then read the Value property to get the value back. There is a way you can make your own selected index property by comparing each item to the Value property and returning the index when the objects match. Hope this helps.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups