I'm sure this is a fairly basic question, but I've been looking all over the
web for days for suggestions on how to do this.
I've got a datagrid that's bound to a dataset on my form. It includes
several columns, the last of which (with the header Quantity) contains int16
values. When a user selects a row, I would like to have a combobox on the
form display the values from 1 to the number in the Quantity column (e.g.,
the selected row has 4 in the quantity column, so the combobox would display
1,2,3,4 for it's items).
I think I can populate the combobox once I've gotten the value from the
Quantity column using something like this:
System.Object[] noBottles = new object[quantity];
for (int i= 1; i<= quantity+1; i++)
{
noBottles[i]=i;
}
cmbNumberOfBottles.Items.AddRange(noBottles);
cmbNumberOfBottles.SelectedIndex[0];
where 'quantity' is the integer from the Quantity column, but for the life
of me I can't get that Quantity number into a useable int format for this.
I'm sure this comes across as Grade-A programming newbie (which I am), but
any help would be appreciated. Also, if my combobox populating method looks
screwy, any advice would be very helpful there as well.
Thanks so much in advance! 2 10546
Robert wrote: I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this.
I've got a datagrid that's bound to a dataset on my form. It includes several columns, the last of which (with the header Quantity) contains int16 values. When a user selects a row, I would like to have a combobox on the form display the values from 1 to the number in the Quantity column (e.g., the selected row has 4 in the quantity column, so the combobox would display 1,2,3,4 for it's items).
I think I can populate the combobox once I've gotten the value from the Quantity column using something like this:
System.Object[] noBottles = new object[quantity]; for (int i= 1; i<= quantity+1; i++) { noBottles[i]=i; } cmbNumberOfBottles.Items.AddRange(noBottles); cmbNumberOfBottles.SelectedIndex[0];
where 'quantity' is the integer from the Quantity column, but for the life of me I can't get that Quantity number into a useable int format for this. I'm sure this comes across as Grade-A programming newbie (which I am), but any help would be appreciated. Also, if my combobox populating method looks screwy, any advice would be very helpful there as well.
Thanks so much in advance!
You need to take the value from the DataTable (or DataSet depending on
what you bound) from the datasource of the datagrid.
I'm a vb guy so I might get the syntax wrong....
DataTable DT = (DataTable) DataGrid.DataSource
Integer I = (Integer) DT.Rows[DataGrid.CurrentRowindex]
Something like that.
Chris
Chris wrote: Robert wrote:
I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this. I've got a datagrid that's bound to a dataset on my form. It includes several columns, the last of which (with the header Quantity) contains int16 values. When a user selects a row, I would like to have a combobox on the form display the values from 1 to the number in the Quantity column (e.g., the selected row has 4 in the quantity column, so the combobox would display 1,2,3,4 for it's items). I think I can populate the combobox once I've gotten the value from the Quantity column using something like this:
System.Object[] noBottles = new object[quantity]; for (int i= 1; i<= quantity+1; i++) { noBottles[i]=i; } cmbNumberOfBottles.Items.AddRange(noBottles); cmbNumberOfBottles.SelectedIndex[0];
where 'quantity' is the integer from the Quantity column, but for the life of me I can't get that Quantity number into a useable int format for this. I'm sure this comes across as Grade-A programming newbie (which I am), but any help would be appreciated. Also, if my combobox populating method looks screwy, any advice would be very helpful there as well.
Thanks so much in advance!
You need to take the value from the DataTable (or DataSet depending on what you bound) from the datasource of the datagrid.
I'm a vb guy so I might get the syntax wrong....
DataTable DT = (DataTable) DataGrid.DataSource Integer I = (Integer) DT.Rows[DataGrid.CurrentRowindex]
Something like that.
Chris
Correction:
Integer I = (Integer) DT.Rows[DataGrid.CurrentRowindex][ColumnName]
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bill C. |
last post by:
Hello,
I know this has been discussed a lot already because I've been searching
around for information the last few weeks.
I'm trying to implement a DataGridComboBoxColumn class. I've found...
|
by: PeterZ |
last post by:
G'day,
After doing much searching and pinching bits of ideas from here there and
everywhere I came up with a fairly 'clean' solution of including a comboBox
into a dataGrid column.
You can...
|
by: TT (Tom Tempelaere) |
last post by:
Hay there,
I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one
(I hope .NET 2.0 supplies one). I based it on this article:...
|
by: John Ninan |
last post by:
I am creating Dynamic Usercontrol in Asp.net application. In this application
I have a combobox(aspx Page). Which contains various items. Based on item
selected I am dynamically populating...
|
by: Aaron Ackerman |
last post by:
I have a bound combobox the appears on a cell within the column of my bound
grid when the user clicks on a cell n(In my vb.net WinForm app).
I am trying to allow the adding of an item to that bound...
|
by: dbuchanan |
last post by:
ComboBox databindng Problem
== How the ComboBox is setup and used:
My comboBox is populated by a lookup table. The ValueMember is the
lookup table's Id and the DisplayMember is the text from a...
|
by: zhuang |
last post by:
Hi,
Adding combobox to datagrid has been posted many times. I have a
datagrid which has multiple combobox columns and normal textbox
columns.
But how could I change other combo box values at...
|
by: fiaolle |
last post by:
Hi
The first set of source code is the class for a combobox in a grid,
hopefully. In the second set of code we try to use the combobox class, but
the grid is empty.
I don't understand how this...
|
by: mansoorali |
last post by:
hi,
am using hittest class in parent form for datagrid and 1 value to be retreived in child form for combobox when i click grid in parent form, am getting the 0 index value by default perhaps i want...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |