473,746 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating a combobox from dataset/datagrid cell value

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;
}
cmbNumberOfBott les.Items.AddRa nge(noBottles);
cmbNumberOfBott les.SelectedInd ex[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!
Nov 17 '05 #1
2 10565
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;
}
cmbNumberOfBott les.Items.AddRa nge(noBottles);
cmbNumberOfBott les.SelectedInd ex[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.DataSo urce
Integer I = (Integer) DT.Rows[DataGrid.Curren tRowindex]

Something like that.

Chris
Nov 17 '05 #2
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;
}
cmbNumberOfBott les.Items.AddRa nge(noBottles);
cmbNumberOfBott les.SelectedInd ex[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.DataSo urce
Integer I = (Integer) DT.Rows[DataGrid.Curren tRowindex]

Something like that.

Chris


Correction:
Integer I = (Integer) DT.Rows[DataGrid.Curren tRowindex][ColumnName]

Chris
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4271
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 several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
3
3029
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 download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
3
6833
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: http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx I have a problem when there are two DataGrid's on one form, and when I switch focus from one grid to the other. To be more precise, when I'm editing a combo box column in one grid, and then click in the combo column of...
2
3344
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 Usercontrols. Problem: When I am populating dynamic user control (ascx) page in Page_load event it works fine for the first list item from combobox. When I change the item in combobox, usercontrols are build properly but value will be same in second...
5
4663
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 combo by allowing the user to dynamically type in the new value directly in the combo box whcih in turn updates the lookup table and then when they have finished leaves that particular cell on the grid with the correct value. Seems...
30
4597
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 corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
0
1820
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 the same row when user change the value of one of the combo box. The textbox value in the same row could be changed by modifying the
1
2098
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 works. The first set of code I downloaded from internet and when i tried it, it worked fine. But when I changed the second part of the code it started to give me trouble. Before I changed the code they used Datacolumns,Datarows and Datatables and...
0
1133
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 the samevalue into combobox what i click into the grid Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp Dim hti As DataGrid.HitTestInfo = sender.HitTest(New...
0
8974
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9350
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8229
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6060
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4586
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.