473,779 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid with dropdowns

In a dataview, I have lots and lots of table relations that make editing
each row kind of a hassle... having to look up ID numbers in 7 different
tables to reference the correct items in the parent tables. And then, once
entered, it's almost impossible to read.

Is there a way to have each field that has a relationship to a table display
the possible choices in a dropdown list? That would be most useful.

Apr 13 '07 #1
1 1332
On Apr 13, 12:21 am, "Peter" <star...@hotmai l.comwrote:
In a dataview, I have lots and lots of table relations that make editing
each row kind of a hassle... having to look up ID numbers in 7 different
tables to reference the correct items in the parent tables. And then, once
entered, it's almost impossible to read.

Is there a way to have each field that has a relationship to a table display
the possible choices in a dropdown list? That would be most useful.
To get you started:

1) Create a DataGridView object and set it to NOT automatically
generate the columns: AutoGenerateCol umns = false

2) Create a DataGridViewCom boBoxColumn object...
Set it's DataSource to the table of "valid values" (child table)...
Set its DisplayMember property to the column name in that table of the
description that you want to see in the drop down...
Set its ValueMember property to the primary key column name or (other
column that represents the foreign key in the parent table column)...
Set the DataPropertyNam e to the name of the column in the parent table
that corresponds to the ValueMember column in the combo box (this is
the parent column that you want to update with the combo selections).

3) Add the combo box column to the data grid

4) Set the DataSource of the data grid view to the parent table

Now instead of seeing arbitrary primary key integers in your columns
you will see that the combo boxes show the proper descriptions and can
be used to update the foreign key integers in the parent table.

Opinion: it is always better to turn off auto column generation with
the DGV, leaving it on will cause the grid to throw many data bind
complete events as you add combo boxes and have to then remove the
auto generated text boxes for the same FK columns. Auto generate is
really, IMO just for RAD prototyping, as once your code starts to
listen to more and more grid events auto generation causes a lot of
"thrashing" that gets complicated to handle. I find it best to
manually add my own custom columns based on the columns collection of
the underlying data source at object construction time.

HTH
Rick
Apr 13 '07 #2

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

Similar topics

1
1115
by: Deepa | last post by:
I am working on a web page which has a datagrid to be populated. The problem is I need to get the data from 2 different tables to bind the 2 columns of the datagrid. I am not sure of how to do this;specifying 2 different datasources for one datagrid. Also the 2nd column in the datagrid needs to be dropdown boxes. How do i insert the dropdowns in the 2nd column Can anyone help me with these? Thanks
0
1118
by: Marc Miller | last post by:
Hi to all, (I apologize that I posted this in dotnet.languages.vb.controls, but I NEED and answer quickly, please) I have an 'employees' datagrid which contains company numbers as labels. When the user clicks 'Update', I have dropdown lists as edititems for the company numbers and populate them from a company table so that the user can change the existing company number. The problem is that the
8
3052
by: Sue | last post by:
I have a datagrid populated with 6 visible read-only labels and several hidden fields. Below the datagrid, I have a table with various textboxes, dropdowns, etc. I've managed to decypher the client-side coding needed for the user to click a "select" button (HTMLButton) in column 0 of the datagrid and have the table objects auto-fill with corresponding values from the dataset row in the datagrid without making a roundtrip to the server. ...
0
916
by: Jeffrey | last post by:
Hi... I have several dropdowns located in a datagrid footer. Now say i modify the selection in dropdown1. I want to refresh the content of the other dropdowns with the result of a database query. How can i do it? Thanks Jef
7
2421
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the Datagrids dynamically using a loop depending on the number of Dropdownlists. The datagrids also have a checkbox template column. Now my problem is that how can I access the values selected by the user from these checkboxes. He checks one or more...
0
878
by: Jim Bancroft | last post by:
Hi everyone, I'm using a DataGrid on one of my web pages and within it I have an ItemTemplate containing a DropDownList. The relevant section looks like this: <asp:datagrid id="DataGrid1" runat="server"> ........ <Columns> <asp:TemplateColumn HeaderText="Division">
2
1685
by: Jim Bancroft | last post by:
This may be a no-brainer, but I'm sure I follow what's happening here... I have a DataGrid with one DropDownList per row. If I select a few DropDown items and postback my page, I can't loop through the DataGridItems unless I rebind my DataGrid. By "can't loop," I mean it's a mighty quick run through-- zero iterations. I was wondering...do I have to rebind on postbacks? If so, what happens if I bind the DataGrid to a different set of...
5
344
by: I am Sam | last post by:
I have a rather complicated problem I need to sort out and wonder if anyone can assist me. The ingredients: Two DropDownList Controls One DataGrid Purpose of Page:
0
2913
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
5
5480
by: Me LK | last post by:
I need to add a line to choose a size into a dropdown . Since I have the dropdown nested inside a datagrid this is not working.When a page displays there are several rows of dropdowns but only the top dropdown has the option added. The others do not. I am using the following code Dim ddlPsize As DropDownList ddlPsize = (itemInfo.Items(0).FindControl("ddlsizes")) ddlPsize.Items.Insert(0, "Choose a Size")
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
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
7485
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
5373
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
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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
3632
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.