|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridViewComboBoxes for numeric fieldsI have several integer fields which have small fixed ramges of values. I
have tried to display them as DataGridViewComboBoxes, but it fails, because the fields are numeric. Is there an easy way round this? At the moment I am displaying them as text boxes, which is not ideal. It doesn't matter if the fields are numeric. Otherwise, it wouldn't work in
a *text* box either. -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull Complex things are made up of lots of simple things. "Philip Sheard" <shea***@myisp.com> wrote in message news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >I have several integer fields which have small fixed ramges of values. I >have tried to display them as DataGridViewComboBoxes, but it fails, because >the fields are numeric. > > Is there an easy way round this? At the moment I am displaying them as > text boxes, which is not ideal. > More information. I get "DataGridViewComboBoxCell value is not valid." when
the form is displayed. Values can be changed, but not saved. Show quote "Philip Sheard" <shea***@myisp.com> wrote in message news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >I have several integer fields which have small fixed ramges of values. I >have tried to display them as DataGridViewComboBoxes, but it fails, because >the fields are numeric. > > Is there an easy way round this? At the moment I am displaying them as > text boxes, which is not ideal. > Need more information. Details and specifics. All you've done so far is give
us the 10,000-foot view of your requirements and end-user experience. Diagnostics require data. -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull Complex things are made up of lots of simple things. "Philip Sheard" <shea***@myisp.com> wrote in message news:OhgYAFkeGHA.1264@TK2MSFTNGP05.phx.gbl... > More information. I get "DataGridViewComboBoxCell value is not valid." > when the form is displayed. Values can be changed, but not saved. > > "Philip Sheard" <shea***@myisp.com> wrote in message > news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >>I have several integer fields which have small fixed ramges of values. I >>have tried to display them as DataGridViewComboBoxes, but it fails, >>because the fields are numeric. >> >> Is there an easy way round this? At the moment I am displaying them as >> text boxes, which is not ideal. >> > > Very well.
My observation is that DataGridViewComboBoxes *never* work for numeric fields. Your argument, apparently based on some kind of Aristotelian view of nature, is that they must work, because DataGridViewTextBoxes can handle numeric fields. As an experiment, create: 1. an SQL Server table, with just 2 columns - an identity field and an int. 2. a VS 2005 project. 3. a data data source, using the new table. 4. a Windows form. 5. a DataGridView, by dragging the data source onto the form. Change the column type of the int field to DataGridViewComboBox, and add some values to the dropdown list. When you run the project, you will get the message "DataGridViewComboBoxCell value is not valid.", repeatedly. Show quote "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message news:uqaYm4leGHA.3792@TK2MSFTNGP03.phx.gbl... > Need more information. Details and specifics. All you've done so far is > give us the 10,000-foot view of your requirements and end-user experience. > Diagnostics require data. > > -- > HTH, > > Kevin Spencer > Microsoft MVP > Professional Numbskull > > Complex things are made up of > lots of simple things. > > "Philip Sheard" <shea***@myisp.com> wrote in message > news:OhgYAFkeGHA.1264@TK2MSFTNGP05.phx.gbl... >> More information. I get "DataGridViewComboBoxCell value is not valid." >> when the form is displayed. Values can be changed, but not saved. >> >> "Philip Sheard" <shea***@myisp.com> wrote in message >> news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >>>I have several integer fields which have small fixed ramges of values. I >>>have tried to display them as DataGridViewComboBoxes, but it fails, >>>because the fields are numeric. >>> >>> Is there an easy way round this? At the moment I am displaying them as >>> text boxes, which is not ideal. >>> >> >> > > Philip Sheard wrote:
Show quote > Very well. I don't know whether I am getting this right. Each row has a single value> > My observation is that DataGridViewComboBoxes *never* work for numeric > fields. Your argument, apparently based on some kind of Aristotelian view > of nature, is that they must work, because DataGridViewTextBoxes can > handle numeric fields. > > As an experiment, create: > 1. an SQL Server table, with just 2 columns - an identity field and an > int. 2. a VS 2005 project. > 3. a data data source, using the new table. > 4. a Windows form. > 5. a DataGridView, by dragging the data source onto the form. > > Change the column type of the int field to DataGridViewComboBox, and add > some values to the dropdown list. When you run the project, you will get > the message "DataGridViewComboBoxCell value is not valid.", repeatedly. > > "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message > news:uqaYm4leGHA.3792@TK2MSFTNGP03.phx.gbl... >> Need more information. Details and specifics. All you've done so far is >> give us the 10,000-foot view of your requirements and end-user >> experience. Diagnostics require data. >> >> -- >> HTH, >> >> Kevin Spencer >> Microsoft MVP >> Professional Numbskull >> >> Complex things are made up of >> lots of simple things. >> >> "Philip Sheard" <shea***@myisp.com> wrote in message >> news:OhgYAFkeGHA.1264@TK2MSFTNGP05.phx.gbl... >>> More information. I get "DataGridViewComboBoxCell value is not valid." >>> when the form is displayed. Values can be changed, but not saved. >>> >>> "Philip Sheard" <shea***@myisp.com> wrote in message >>> news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >>>>I have several integer fields which have small fixed ramges of values. I >>>>have tried to display them as DataGridViewComboBoxes, but it fails, >>>>because the fields are numeric. >>>> >>>> Is there an easy way round this? At the moment I am displaying them as >>>> text boxes, which is not ideal. >>>> >>> >>> >> >> for the int column; there is not a multiple of values are needed by the coomboboxes. So it seams to me that you would need to provide multiple values in the row for the combobox as a detail of the main datagrid. OK, Philip, just to be sure I wasn't being "Aristotelian," I created a new
project, added a DataSource using the SQL Server Northwind database, two tables, Employees (ID (int(, LastName, FirstName), and Orders (EmployeeID and OrderDate). I dragged the Orders table to the form, and edited the EmployeeID column to use a DataGridViewComboBoxColumn, with Employees as the DataSource, Employees.EmployeeID as the DataMember, and Employees.EmployeeeID as the Value Member. I then ran the form, with *no problems*. The Employee Number showed up in the ComboBox column, and I was able to change it to the Employee ID of any Employee in the database. I've been putting in 70-hour weeks for several months now, so I hope you appreciate it! ;-) -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull The man who questions opinions is wise. The man who quarrels with facts is a fool. "Philip Sheard" <shea***@myisp.com> wrote in message news:OWEZQk2eGHA.3900@TK2MSFTNGP05.phx.gbl... > Very well. > > My observation is that DataGridViewComboBoxes *never* work for numeric > fields. Your argument, apparently based on some kind of Aristotelian view > of nature, is that they must work, because DataGridViewTextBoxes can > handle numeric fields. > > As an experiment, create: > 1. an SQL Server table, with just 2 columns - an identity field and an > int. > 2. a VS 2005 project. > 3. a data data source, using the new table. > 4. a Windows form. > 5. a DataGridView, by dragging the data source onto the form. > > Change the column type of the int field to DataGridViewComboBox, and add > some values to the dropdown list. When you run the project, you will get > the message "DataGridViewComboBoxCell value is not valid.", repeatedly. > > "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message > news:uqaYm4leGHA.3792@TK2MSFTNGP03.phx.gbl... >> Need more information. Details and specifics. All you've done so far is >> give us the 10,000-foot view of your requirements and end-user >> experience. Diagnostics require data. >> >> -- >> HTH, >> >> Kevin Spencer >> Microsoft MVP >> Professional Numbskull >> >> Complex things are made up of >> lots of simple things. >> >> "Philip Sheard" <shea***@myisp.com> wrote in message >> news:OhgYAFkeGHA.1264@TK2MSFTNGP05.phx.gbl... >>> More information. I get "DataGridViewComboBoxCell value is not valid." >>> when the form is displayed. Values can be changed, but not saved. >>> >>> "Philip Sheard" <shea***@myisp.com> wrote in message >>> news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >>>>I have several integer fields which have small fixed ramges of values. I >>>>have tried to display them as DataGridViewComboBoxes, but it fails, >>>>because the fields are numeric. >>>> >>>> Is there an easy way round this? At the moment I am displaying them as >>>> text boxes, which is not ideal. >>>> >>> >>> >> >> > > Yes, of course it works when the values are in another table, but not when
they are stored in the combo box itself. Show quote "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message news:%23i%23$ys5eGHA.4776@TK2MSFTNGP05.phx.gbl... > OK, Philip, just to be sure I wasn't being "Aristotelian," I created a new > project, added a DataSource using the SQL Server Northwind database, two > tables, Employees (ID (int(, LastName, FirstName), and Orders (EmployeeID > and OrderDate). I dragged the Orders table to the form, and edited the > EmployeeID column to use a DataGridViewComboBoxColumn, with Employees as > the DataSource, Employees.EmployeeID as the DataMember, and > Employees.EmployeeeID as the Value Member. I then ran the form, with *no > problems*. The Employee Number showed up in the ComboBox column, and I was > able to change it to the Employee ID of any Employee in the database. > > I've been putting in 70-hour weeks for several months now, so I hope you > appreciate it! ;-) > > -- > HTH, > > Kevin Spencer > Microsoft MVP > Professional Numbskull > > The man who questions opinions is wise. > The man who quarrels with facts is a fool. > > "Philip Sheard" <shea***@myisp.com> wrote in message > news:OWEZQk2eGHA.3900@TK2MSFTNGP05.phx.gbl... >> Very well. >> >> My observation is that DataGridViewComboBoxes *never* work for numeric >> fields. Your argument, apparently based on some kind of Aristotelian view >> of nature, is that they must work, because DataGridViewTextBoxes can >> handle numeric fields. >> >> As an experiment, create: >> 1. an SQL Server table, with just 2 columns - an identity field and an >> int. >> 2. a VS 2005 project. >> 3. a data data source, using the new table. >> 4. a Windows form. >> 5. a DataGridView, by dragging the data source onto the form. >> >> Change the column type of the int field to DataGridViewComboBox, and add >> some values to the dropdown list. When you run the project, you will get >> the message "DataGridViewComboBoxCell value is not valid.", repeatedly. >> >> "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message >> news:uqaYm4leGHA.3792@TK2MSFTNGP03.phx.gbl... >>> Need more information. Details and specifics. All you've done so far is >>> give us the 10,000-foot view of your requirements and end-user >>> experience. Diagnostics require data. >>> >>> -- >>> HTH, >>> >>> Kevin Spencer >>> Microsoft MVP >>> Professional Numbskull >>> >>> Complex things are made up of >>> lots of simple things. >>> >>> "Philip Sheard" <shea***@myisp.com> wrote in message >>> news:OhgYAFkeGHA.1264@TK2MSFTNGP05.phx.gbl... >>>> More information. I get "DataGridViewComboBoxCell value is not valid." >>>> when the form is displayed. Values can be changed, but not saved. >>>> >>>> "Philip Sheard" <shea***@myisp.com> wrote in message >>>> news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >>>>>I have several integer fields which have small fixed ramges of values. >>>>>I have tried to display them as DataGridViewComboBoxes, but it fails, >>>>>because the fields are numeric. >>>>> >>>>> Is there an easy way round this? At the moment I am displaying them as >>>>> text boxes, which is not ideal. >>>>> >>>> >>>> >>> >>> >> >> > > >> My observation is that DataGridViewComboBoxes *never* work for numeric The field I used from the Employees table *is* a numeric field. And the >> fields. > Yes, of course it works when the values are in another table, but not when > they are stored in the combo box itself. values in it are stored in the Items Collection of the combo box itself. There is no other place to store them. The problem you are having therefore has nothing to do with numeric fields. It has to do with how you're putting values into the DataGridViewComboBoxColumn, or what those values are. For example, if the column is bound to a table data source, the values must be in the table it is bound to or they will not be valid. There are 4 distinct properties of a DataGridViewComboBoxColumn that come into play when binding it to a table: DataSource: The table (object) that the Items Collection is populated from. If this property is set, you can not use the Items Collection to populate the DataGridViewComboBoxColumn. ValueMember: The column in the table that holds the underlying value for each Item (row). DisplayMember: The column in the table that holds the displayed value for each Item (row). DataPropertyName: The column in the table (BindingSource) that the DataGridView is bound to. When the value in the DataGridViewComboBoxCell changes, the value in the BindingSource is changed. The Items property can be used when the DataSource is not set. It is important to remember that a DataGridViewComboBoxColumn can be bound to 0, 1, or 2 different tables. In your case, it sounds like you only want to bind to a single table. Therefore, the DataSource property should not be set. Finally, make sure that your Data Type (the type that you are assigning to the Items in the Items Collection) is correct if you populate the Items Collection by hand. The underlying value must be of the same Data Type as the Data Type of the table column that the DataPropertyName is referring to. The value displayed will almost always be a string (although it may be an image). In any case, it must be something human-readable. For more information, see: http://msdn2.microsoft.com/en-US/library/system.windows.forms.datagridviewcomboboxcolumn.aspx -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull The man who questions opinions is wise. The man who quarrels with facts is a fool. "Philip Sheard" <shea***@myisp.com> wrote in message news:%23mheyF$eGHA.3484@TK2MSFTNGP02.phx.gbl... > Yes, of course it works when the values are in another table, but not when > they are stored in the combo box itself. > > "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message > news:%23i%23$ys5eGHA.4776@TK2MSFTNGP05.phx.gbl... >> OK, Philip, just to be sure I wasn't being "Aristotelian," I created a >> new project, added a DataSource using the SQL Server Northwind database, >> two tables, Employees (ID (int(, LastName, FirstName), and Orders >> (EmployeeID and OrderDate). I dragged the Orders table to the form, and >> edited the EmployeeID column to use a DataGridViewComboBoxColumn, with >> Employees as the DataSource, Employees.EmployeeID as the DataMember, and >> Employees.EmployeeeID as the Value Member. I then ran the form, with *no >> problems*. The Employee Number showed up in the ComboBox column, and I >> was able to change it to the Employee ID of any Employee in the database. >> >> I've been putting in 70-hour weeks for several months now, so I hope you >> appreciate it! ;-) >> >> -- >> HTH, >> >> Kevin Spencer >> Microsoft MVP >> Professional Numbskull >> >> The man who questions opinions is wise. >> The man who quarrels with facts is a fool. >> >> "Philip Sheard" <shea***@myisp.com> wrote in message >> news:OWEZQk2eGHA.3900@TK2MSFTNGP05.phx.gbl... >>> Very well. >>> >>> My observation is that DataGridViewComboBoxes *never* work for numeric >>> fields. Your argument, apparently based on some kind of Aristotelian >>> view of nature, is that they must work, because DataGridViewTextBoxes >>> can handle numeric fields. >>> >>> As an experiment, create: >>> 1. an SQL Server table, with just 2 columns - an identity field and an >>> int. >>> 2. a VS 2005 project. >>> 3. a data data source, using the new table. >>> 4. a Windows form. >>> 5. a DataGridView, by dragging the data source onto the form. >>> >>> Change the column type of the int field to DataGridViewComboBox, and add >>> some values to the dropdown list. When you run the project, you will get >>> the message "DataGridViewComboBoxCell value is not valid.", repeatedly. >>> >>> "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message >>> news:uqaYm4leGHA.3792@TK2MSFTNGP03.phx.gbl... >>>> Need more information. Details and specifics. All you've done so far is >>>> give us the 10,000-foot view of your requirements and end-user >>>> experience. Diagnostics require data. >>>> >>>> -- >>>> HTH, >>>> >>>> Kevin Spencer >>>> Microsoft MVP >>>> Professional Numbskull >>>> >>>> Complex things are made up of >>>> lots of simple things. >>>> >>>> "Philip Sheard" <shea***@myisp.com> wrote in message >>>> news:OhgYAFkeGHA.1264@TK2MSFTNGP05.phx.gbl... >>>>> More information. I get "DataGridViewComboBoxCell value is not valid." >>>>> when the form is displayed. Values can be changed, but not saved. >>>>> >>>>> "Philip Sheard" <shea***@myisp.com> wrote in message >>>>> news:OYHYMQfeGHA.5040@TK2MSFTNGP03.phx.gbl... >>>>>>I have several integer fields which have small fixed ramges of values. >>>>>>I have tried to display them as DataGridViewComboBoxes, but it fails, >>>>>>because the fields are numeric. >>>>>> >>>>>> Is there an easy way round this? At the moment I am displaying them >>>>>> as text boxes, which is not ideal. >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > |
|||||||||||||||||||||||