473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"InvalidArgument=Value of '0' is not valid for 'index'

I am facing a problem in binding the datagridviewcombo box cell.

Expand|Select|Wrap|Line Numbers
  1. DataGridViewComboBoxCell cmbControlTypes= new DataGridViewComboBoxCell();
  2.  
  3. cmbControlTypes.DataSource = result.resultTable;
  4. cmbControlTypes.DisplayMember = "name";
  5. cmbControlTypes.ValueMember = "id";
after binding the comboboxcell and adding it to row.
when i access the item collection as follows.

Expand|Select|Wrap|Line Numbers
  1. cmbControlTypes.Value = cmbControlTypes.Items[0]
i am getting an error

"InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index"

is there any solution for above problem?.
Mar 2 '10 #1

✓ answered by Jaydeep Ramavat

I have figured out the issue by following code.

In below code loadcontrol function loads table and bind it to the cmbcontroltypes combo.

Expand|Select|Wrap|Line Numbers
  1.                DataTable dtReturn = loadControlTypes(cmbControlTypes);
  2.  
  3.                 if (dtReturn != null)
  4.                 {
  5.                     if (dtReturn.Rows.Count > 0)
  6.                     {
  7.                         cmbControlTypes.Value = dtReturn.Rows[0][0];                        
  8.                     }
  9.                 }
I can get the member at 0 position at selected value in datagridviewcomboboxcell.

Thanks and Regards
Jay

4 10297
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 2 '10 #2
tlhintoq
3,525 Expert 2GB
is there any solution for above problem?.
Yes. Don't presume you have items. Get used to range checking.

Expand|Select|Wrap|Line Numbers
  1. if (cmbControlTypes.Items.Count > 0)
  2. {
  3.  
  4. cmbControlTypes.Value = cmbControlTypes.Items[0]
  5.  
  6. }
Mar 2 '10 #3
Thanks for your writing instruction and reply.

Actually i was also doing count on items property.
In my application i am getting count = 7, so not a problem.
Mar 2 '10 #4
I have figured out the issue by following code.

In below code loadcontrol function loads table and bind it to the cmbcontroltypes combo.

Expand|Select|Wrap|Line Numbers
  1.                DataTable dtReturn = loadControlTypes(cmbControlTypes);
  2.  
  3.                 if (dtReturn != null)
  4.                 {
  5.                     if (dtReturn.Rows.Count > 0)
  6.                     {
  7.                         cmbControlTypes.Value = dtReturn.Rows[0][0];                        
  8.                     }
  9.                 }
I can get the member at 0 position at selected value in datagridviewcomboboxcell.

Thanks and Regards
Jay
Mar 19 '10 #5

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

Similar topics

10
by: dof | last post by:
I'm trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D #include stuff .... ...
11
by: ike | last post by:
Could you please give your opinion on the portability of this code? /* -------- begin findindex.c -------- */ struct Foo { int junk0; }; struct Bar { int junk1; struct Foo foo; int junk2; }; ...
3
by: Eric Davies | last post by:
We've implemented a 5D box data type and have implemented both RTree and GiST access methods under PostgresSQL 7.4 and PostgresSQL 7.4.1. The 5D box internally looks like: struct Box5D{ float...
14
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
8
by: ALiX | last post by:
Hi all, In my code I use different vectors of the same size to hold some data. At some point I need to iterate through all vectors at the same time. Now, the question is what type should the...
11
by: Chris | last post by:
I have a simple search feature that searches 3 fields in 3 separate tables in a MySQL db, and I'm getting an 'undefined index' error, but only in the first section (first table)of the results. The...
96
by: zzbbaadd | last post by:
What's with the index() function of lists throwing an exception on not found? Let's hope this is rectified in Python 3. If nothing else, add a function that doesn't throw an exception. There are a...
12
by: TkNeo | last post by:
WHAT ? This is crazy
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hello As I debug the C# code with a break point and by pressing F11 I eventually get a message stating: ContextSwitchDeadlock was detected Message: The CLR has been unable to transition from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.