473,655 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"InvalidArgumen t=Value of '0' is not valid for 'index'

12 New Member
I am facing a problem in binding the datagridviewcom bo 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

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

is there any solution for above problem?.
Mar 2 '10 #1
4 10316
tlhintoq
3,525 Recognized Expert Specialist
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 Recognized Expert Specialist
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
Jaydeep Ramavat
12 New Member
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
Jaydeep Ramavat
12 New Member
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 datagridviewcom boboxcell.

Thanks and Regards
Jay
Mar 19 '10 #5

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

Similar topics

10
9080
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 .... const enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX}; RWCString MESSAGES; <--------------------- MESSAGES = "MESSAGE_A";
11
2829
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; }; int findindex(struct Bar * bars, struct Foo * fooptr) /* Pre: * bars points to (the first element of) an array of Bar.
3
2196
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 minBounds; float maxBounds; }; and so takes up 40 bytes and is of fixed length. The GiST access methods are basically a generalization of the 2D box indexing access methods from Refraction Research's PostGIS.
14
2373
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 hassel with a multi-dimensional array. Is there such an object in VB.Net? Dim obj As someCollectionObj obj.Add("parmA1", "parmA2", "parmA3") obj.Add("parmB1", "parmB2", "parmB3") ....
8
1612
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 index variable have? size_t? vector<X>::size_type? vector<Y>::size_type? Example code: -------------------- vector<X> xv; vector<Y> yv;
11
498
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 undefined index is tied to the docs.projID in the "if ($row_search == 1)". This if statement is there to control to format of the link as pages are in different depths of subfolders depending on security needs. Googling this sort of error...
96
4558
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 million situations where you can have an item not be in a list and it is not an exception situation.
12
1969
by: TkNeo | last post by:
WHAT ? This is crazy
6
4315
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 Alvin Leader
1
3002
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 COM context 0x17aeb8 to COM context 0x17abd8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages.
0
8816
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
8710
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...
1
8497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7310
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
5627
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
4150
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
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
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.