|
-
May 5th, 2005, 03:24 AM
#1
Thread Starter
Frenzied Member
combox box in datagrid
Hello,
I am developing an application for a stock control system. I am using a datagrid and the customer wants a combo box in one of the columns, to make selection easier.
I my database l have 2 tables, customer and parts. Relationship a customer can order many parts. So the grid will display all the different parts. and the user will click on the customer column and select the customer who wants this part.
example. PartID, Name, price, quantity, customer are the column headers in the datagrid.
Thanks very much for your help in advance,
Steve
-
May 5th, 2005, 11:11 AM
#2
Frenzied Member
Re: combox box in datagrid
There's nothing built in with the .NET DataGrid that supports combo boxes. Alll they offer is text and bool columns. Check out codeproject.com - there's a few examples.
-
May 10th, 2005, 01:50 AM
#3
Member
Re: combox box in datagrid
Steve_rm, this can be done by adding a template column to your datagrid. There you created a drowdownlist and give it a name for example dropCustomer. Next what you want to do is make your datagrid, like you are doing now. After that you will have to browse threw all the row of the datagrid and 'find the control' you will use the functie findcontrol and search for "dropCustomer". Next you will parse the founded control to a dropdownlist. So now you can access your dropdownlist , now all you have to do is to get all the custumors out of the database and into your dropdownlist. I would recomment a datareader.
Code:
while(dr.read()){
foundDropDown.Item.Add(dr[0].toString());
}
something like that.
Here is my code I used to get a checkbox in the datagrid. And I my value in my database == true then I check the checkbox.
Code for in your asp page - The template column
Code:
<asp:TemplateColumn HeaderText="TIER1?">
<HeaderStyle HorizontalAlign="Center" Width="65px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:DropDownList id="dropCustomer" Enabled="True" Runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
Code for in your C# page
So don't forget FIRST fill your datagrid like you normaly do. The will result in showing a table wit your parts and empty dropdownlists for your custumor.
Now we will fill op your customers dropdownlists
Go into a for lus for 1 to the length of your datagrid. (I used my dataset to count my rows, you can just use your datagird to count your rows)
Code:
DataRowCollection myCol = common.MyDs.Tables[0].Columns[0].Table.Rows;
for(int i = 0; i< myCol.Count ; i++)
{
...
}
Next we are making a nieuw datagrid item (this will be your dropdownlist)
Gridfirms is the name of my datagrid and i is the nummer of the row.
Code:
DataGridItem temp1 = GridFirms.Items[i];
So now we have a row now lets make a new dropdownlist
Code:
System.Web.UI.WebControls.DropDownList newDropDown;
So we got the row and we have a dropdowlist, now lets find our dropdownlist of your template column and put it into or new made dropdownlist
newDropDown = (System.Web.UI.WebControls.DropDownList)temp1.FindControl("dropCustomer");
So now newDropDown is your dropdown in your datagrid, so we can now start adding items to the dropdownlist.
for example
Code:
newDropDown.Items.Add("Item1");
newDropDown.Items.Add("Item2");
This will result in a dropdownlist in your datagrid with 2 values , "item1" and "item2".
Also look at an other topic.. I had the same problem my, but I've posted my solution there ..
MY SOLUTION TO THE SAME PROBLEM
-
May 10th, 2005, 02:58 AM
#4
Thread Starter
Frenzied Member
Re: combox box in datagrid
Hello,
Thanks for your help and l will check this out.
Steve
-
May 10th, 2005, 08:17 AM
#5
Member
Re: combox box in datagrid
 Originally Posted by steve_rm
Hello,
Thanks for your help and l will check this out.
Steve
Cool, and plz let us know if it worked
-
May 11th, 2005, 02:05 AM
#6
Addicted Member
Re: combox box in datagrid
Fill Comber box with cumtomer
and add this combo box on DataGrid
DataGrid.Controls.Add(combobox);
On Combo Box Event
ComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbItemName.SelectionChangeCommitted
DataGrid[DataGrid.CurrentRowIndex, 2] = comboBox.text
-
May 11th, 2005, 02:47 AM
#7
Member
Re: combox box in datagrid
I've tryed what you say Waseemalisyed but with your code you only have one combo box, linked to your datagrid, and I think he need a combo box for each record of the datagrid.
Or am I wrong ...??
-
May 11th, 2005, 04:42 AM
#8
Addicted Member
Re: combox box in datagrid
Add multiple combo on grid
combobox1
combobox2
combobox3
combobox4
DataGrid.Controls.Add(combobox1)
DataGrid.Controls.Add(combobox2)
DataGrid.Controls.Add(combobox3)
DataGrid.Controls.Add(combobox4)
u can do this
-
May 12th, 2005, 01:24 AM
#9
Member
Re: combox box in datagrid
not if you don't know how many records you are going to have + these comboboxes are not shown in your datagrid but outside the grid.
So that is not the way to go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|