473,779 Members | 2,092 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 14773
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
3961
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
7203
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
2179
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
17811
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
1429
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
10305
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
10137
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
9928
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
8959
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...
0
6724
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
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?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
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.