473,769 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridViewCom boBox: allow Value that is NOT in Items list

I understand that the Value put into a DataGridViewCom boBoxCell has to be a
member of the Items list or an exception is thrown.

I also understand that you can override that exception by handling the
DataError event and just doing nothing in the circumstance that caused the
error.

Here's my situation: I would like to allow the user to EITHER select an item
from the ComboBox (in a DataGridView) OR type in a new value of their own.

I've handled the EditingControlS howing event to change the DropDownStyle of
the editing control to DropDown (rather than DropDownList). This allows me to
type something new into the edit box of the ComboBox.

Then I handled the CellEndEdit event to snag the Text from the editing
ComboBox control. I take that Text and put it into the Value of the
DataGridViewCom boBoxCell. This triggers the exception.

If I override that exception, things move along OK, except that that cell
now takes the value of the first item in the ComboBox Items list.

Is there a way to force the ComboBox to accept the new value?

Or perhaps a different way to work around this:
Is there a way to have the DataGridView column be of the Text type, but
attach a ComboBox instead of a TextBox for editing. Then take whatever the
Text value is from the ComboBox EditingControl and put that into the
DataGridViewTex tBoxCell?

I hope: 1) this makes sense, and 2) someone out there knows how to pull this
off.

Thanks.
Nov 3 '08 #1
2 14772
Your combo box is using an data source, so you definitely have a
table(or another source) associated with it. Jut add that value as new
row in that table before the DataGridView validates the cell content.
You can try to add the value in the table when the user has finished
editing.
Validation event is fired after the end-editing(or whatever) event is fired.

Once you add the row in the underlying table, the validation will/should
succeed.

I have not tried this, but it should definitely work. I will try it out
tomorrow.

Thanks & Regards,
Ashutosh Bhawasinka

DrDBF wrote:
I understand that the Value put into a DataGridViewCom boBoxCell has to be a
member of the Items list or an exception is thrown.

I also understand that you can override that exception by handling the
DataError event and just doing nothing in the circumstance that caused the
error.

Here's my situation: I would like to allow the user to EITHER select an item
from the ComboBox (in a DataGridView) OR type in a new value of their own.

I've handled the EditingControlS howing event to change the DropDownStyle of
the editing control to DropDown (rather than DropDownList). This allows me to
type something new into the edit box of the ComboBox.

Then I handled the CellEndEdit event to snag the Text from the editing
ComboBox control. I take that Text and put it into the Value of the
DataGridViewCom boBoxCell. This triggers the exception.

If I override that exception, things move along OK, except that that cell
now takes the value of the first item in the ComboBox Items list.

Is there a way to force the ComboBox to accept the new value?

Or perhaps a different way to work around this:
Is there a way to have the DataGridView column be of the Text type, but
attach a ComboBox instead of a TextBox for editing. Then take whatever the
Text value is from the ComboBox EditingControl and put that into the
DataGridViewTex tBoxCell?

I hope: 1) this makes sense, and 2) someone out there knows how to pull this
off.

Thanks.
Nov 3 '08 #2
Sorry, I forgot to mention that it is NOT actually data bound. I fill the
Items list manually. I'll grant that I am using the results from a
DataReader, but I manually loop through the DataReader
while (reader.Read())
{ dgvCo.Items.Add (reader.GetStri ng(0)) }

And while I think your solution would work, I don't actually want to save
the Value that the user types. To be more specific on what I'm trying to
accomplish.... The DataGridView is for entering an invoice. Most of the
invoice items have a specific "name" but I want to possibility of a "Misc"
invoice item into which the user can type whatever description of that
invoice line item they want. I don't want or need this saved into the
database of invoice items since it will vary with each invoice.

"Ashutosh Bhawasinka" wrote:
Your combo box is using an data source, so you definitely have a
table(or another source) associated with it. Jut add that value as new
row in that table before the DataGridView validates the cell content.
You can try to add the value in the table when the user has finished
editing.
Validation event is fired after the end-editing(or whatever) event is fired.

Once you add the row in the underlying table, the validation will/should
succeed.

I have not tried this, but it should definitely work. I will try it out
tomorrow.

Thanks & Regards,
Ashutosh Bhawasinka
Nov 3 '08 #3

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

Similar topics

33
3960
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433)) s1.bind((host, port)) s1.listen(1) cn, addr = s1.accept() def VB_SCRIPT():
32
7200
by: jamieexley | last post by:
what are the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004????
2
2178
by: Sehboo | last post by:
I am trying to use key value pair list, but I don't want to use sorted list because it messes up my order. I am not sure what other options I have. Can anybody point? Thanks
4
17810
by: semomaniz | last post by:
I have a list box that has a list of roles defined. List of roles are binded to the list box in page load event. I am trying to retrieve the selected role from the text box but i am getting a null reference error even though one of the item is selected. below is the code that gives me null reference. String role = lstRole.SelectedItem.ToString(); Label1.Text = role; I even tried using the code below and all i get is null value....
7
2042
vikas251074
by: vikas251074 | last post by:
Can I assign value to cookies immediately after selecting a value from list? <select name="vlan_name" style="width:150px "> <%set rs = conn.execute("select vlan_name from vlan_master order by vlan_name") dim v_lan do while not rs.eof%> <option value="<%=rs("vlan_name")%>"><%=rs("vlan_name")%></option> <% rs.movenext loop%> </select>
1
1484
by: AarthiVedhavalli | last post by:
Hi, In my C# web application I have a list box whic is binded to database. What i need now is , if i double click a value in list box that vale should be added to a dropdown list.. Any suggestions??
1
7240
by: libish | last post by:
can we add a value to a list item?? i got a list with some list members here can we add a value to that list item??? ie. suppose a list contains items like "item1" "item2" "item3" etc...
0
1428
vikas251074
by: vikas251074 | last post by:
I am using Oracle 9i and ASP I have empno, empname, designation, category, dob. Category have two option 'S' or 'O' When I enter empno, empname, designation, category and dob and when I press enter key all the data remains on the form but only list value is lost. what should I do ? How can I solve this. <%@ Language=VBScript%>
0
1531
by: bullfrog83 | last post by:
I'm working in an Access project (.adp) that's linked to a SQL Server db. What I can't get to work is the Allow Value List Edits option for a combobox. It works fine in a .accdb file. However, even though I have the option set to Yes and specified a List Items Edit Form, the small, somewhat opaque button at the bottom of the drop-down list doesn't appear. In Access Options I have Allow Full Menus selected. What am I missing?
0
9579
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
9422
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
10035
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
8863
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
7403
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
5293
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
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
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
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.