473,473 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGridView problem

37 New Member
Hi,

I have a dataGridView with textBoxColumn. I have an Enum type with 3 values. The property ValueType is set to the enum

dataGridViewTextBoxColumn1.ValueType = typeof( EnumType );

But when I enter a value that is not in the Enum I get an Error Window that tells me that I am not handled exception in System.Enum.Parse(...). How can I handle this exception ( where??? ).

The Exception
Dec 26 '07 #1
7 1058
Plater
7,872 Recognized Expert Expert
You would have to put a try/catch block around the insertion.

But you should read what you are saying.
You want the column to be of the enum values...but you are trying to insert a non-enum value.
That would be like having an int column and wondering why "jane doe" is not allowed to be inserted into it.
Dec 26 '07 #2
mynkow
37 New Member
That is the point. I want to catch values that are not in the Enum.
Dec 26 '07 #3
Plater
7,872 Recognized Expert Expert
Does this work?
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3. EnumType mytest = (EnumType)SomeValue;
  4. }
  5. catch(Exception ee)
  6. {
  7. //didn't work
  8. }
  9.  
Dec 26 '07 #4
mynkow
37 New Member
No.

If this can help...
Dec 26 '07 #5
Plater
7,872 Recognized Expert Expert
Have you tried any the events for the DataGridView object?

Possibly usefull events:
myDataGridView.CellParsing
myDataGridView.CellErrorTextChanged
myDataGridView.CellErrorTextNeeded
Dec 26 '07 #6
mynkow
37 New Member
When occurred this kind of exception the DataGridView calls "DataError" event where I can handle the Exception.

Expand|Select|Wrap|Line Numbers
  1. private void dataGridView1_DataError( object sender, DataGridViewDataErrorEventArgs e )
  2.         {
  3.             System.Diagnostics.Debug.WriteLine( e.Exception.Message );
  4.         }
  5.  
Dec 27 '07 #7
Plater
7,872 Recognized Expert Expert
Hehe, you know I went looking for a DataError event and somehow managed to miss that exact one.
Good find.
Dec 27 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
1
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business...
1
by: sapkal.manish | last post by:
Question : How can I find actual row position of DataTable in DataGridView when DataTable is sorted / My source code like this Private WithEvent dgvInwDet as new DataGridView Private...
1
by: Rich | last post by:
Hello, I am reading data from a sql server table that is under replication. This table has the replicatin GUID column that is generated with replicatin. I am reading the data from a...
2
by: Rich | last post by:
Hello, Following an example at http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker) on binding a dataRelation to a Datagridview for sqlClient, I was able to view rows...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
11
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
3
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
1
by: Jeff | last post by:
Hey ..NET 2.0 I've created a User Control which contain a DataGridView. This User Control is displayed on a TabPage. This TabPage is added to the TabControl during runtime. The problem is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.