Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a datagridview in one form which has a quantity field. it contains int type of numbers. I want to be able to create a combobox field in another datagridview in another form which will get a range depending on the quantity in the other form.

for example the quantity I input in the first form is 5.When I save it I want to show in the other form a combobox which has values that range from 1 to 5.

I am using C# and visual studio 2010

C#
this.itemqtyDataGridViewTextBoxColumn.DataSource = Enumerable.Range(0, quantityfromtheotherform).ToArray();
Posted

C#
for (int i = 1; i <= num; i++)
            {
                comboBox1.Items.Add(i);
            }
 
Share this answer
 
Comments
robert_54 18-Dec-12 12:55pm    
So how do i get the data from the quantity column? if i have 2 rows with different quantities then the comboboxes in the other form would also depend on that.

example:

quantity combobox
5 1 to 5
10 1 to 10
You could try setting different data source to the cell than for the grid.

like this:
C#
DataGridViewComboBoxColumn newColumn = new DataGridViewComboBoxColumn();
newColumn.Name = "abc";
newColumn.DataSource = new string[] { "a", "b", "c" };
dataGridView1.Columns.Add(newColumn);

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(row.Cells["abc"]);
    cell.DataSource = new string[] { "a", "c" };
}

more information available here[^]
 
Share this answer
 
Comments
robert_54 19-Dec-12 9:49am    
how do i get the datasource for my quantity column from another form or database? because my quantity column has different quantities.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900