473,671 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList.Remov eAt(i)

Hi All,

I've done the same things for another array list like resetting the
datasource and its working fine but this time for a separate case i still
get the same error "index out of range"
And like before, the arraylist that is being binded is deleting correctly
from 4 items down to 3 etc. Do anyone have any ideas?

Thanks in advance

Alex Ting

""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:Y8******** ******@cpmsftng xa06.phx.gbl...

Hi Alex,

You should set DataGridTableSt yle's MappingName to "ArrayList" , then set
DataGridColumnS tyle's MappingName to Arraylist's public property.
When deleting the arraylist member, you should refer to the
CurrencyManager (Manages the collection of BindingManagerB ase objects )
which can get from BindingContext item.
You should decrease CurrencyManager .Position property.
Then, you can delete an item of arraylist and update the CurrencyManager .

There is a sample project(You should download the entire project from a
link in this article) in the post I last replied you. It provides you a
detailed implementation of operating the Arraylist databinding. This sample project works well on my machine, and I think it will meet your need

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Alex Ting" <at***@learning fast.com>
| References: <Oa************ *@TK2MSFTNGP11. phx.gbl>
<Mh************ **@cpmsftngxa06 .phx.gbl>
| Subject: Re: ArrayList.Remov eAt(i)
| Date: Thu, 6 Nov 2003 13:34:30 +1100
| Lines: 285
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <e8************ *@TK2MSFTNGP10. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: learningfast2.l earnfast.monash .edu.au 130.194.247.2
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1970 66 | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| Hi Jeff,
|
| Thanks for your reply.
|
| the getQuestions simply returns the arrayList
|
| public Learningfast.QG M.QuizList getQuestions()
|
| {
|
| return this.myQuestion s;
|
| }
|
| The mapping name is set to this but this is still not working. I even set | the mapping name to "ArrayList" but to no avail.
|
| Thanks in advance.
|
| Alex Ting
|
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
| news:Mh******** ******@cpmsftng xa06.phx.gbl...
| >
| > Hi Alex,
| >
| > Sorry for letting you wait for so long time.
| > I think your code snipet is not integrated. There is nothing code
related
| > to getQuestions() method.
| > But I still can give you some suggestion.
| > For datagrid to bind to the arraylist, you should set the MappingName
| > property to "ArrayList" not others. This rule can be found in MSDN
| document
| > in DataGrid(WinFor m).
| > I think if you set the correct binding, the datagrid will reflect the
| > source arraylist correctly.
| >
| > For a sample of how to bind arraylist to datagrid, you can refer to:
| > http://www.syncfusion.com/FAQ/WinFor...c43c.asp#q818q
| >
| > If you still have anything unclear, please feel free to let me know.
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Alex Ting" <at***@learning fast.com>
| > | Subject: ArrayList.Remov eAt(i)
| > | Date: Fri, 31 Oct 2003 16:30:57 +1100
| > | Lines: 201
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <Oa************ *@TK2MSFTNGP11. phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| > | NNTP-Posting-Host: learningfast2.l earnfast.monash .edu.au 130.194.247.2 | > | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| > | Xref: cpmsftngxa06.ph x.gbl
| microsoft.publi c.dotnet.langua ges.csharp:1956 20
| > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
| > |
| > | Hi Everybody,
| > |
| > | I have an issue about deleting an object from an arrayList.
| > |
| > | I've bounded a datagrid using this code
| > | where it will first run through all of the code in loadQuestions() and | > bind
| > | a arrayList to the datagrid.
| > |
| > | private void BindQuestions()
| > |
| > | {
| > |
| > | dataGridQuestio ns.DataSource= this.AppQuiz.ge tQuestions();
| > |
| > | this.toolBarBtn Save.Enabled=tr ue;
| > |
| > | this.toolBarBtn Del.Enabled=tru e;
| > |
| > | }
| > |
| > |
| > |
| > | public void loadQuestions()
| > |
| > | {
| > |
| > | this.BindQuesti ons();//this.AppQuiz.ge tQuestions();//AppQuiz();
| > |
| > | if(this.DataGri dSet==false)
| > |
| > | {
| > |
| > | DataGridTableSt yle gs = new DataGridTableSt yle(); // gs = Grid | > Style
| > |
| > |
| > | gs.MappingName = AppQuiz.getQues tions().GetType ().Name;
| > | //dummyDataArr.Ge tType().Name;
| > |
| > | gs.AllowSorting = true;
| > |
| > | gs.AlternatingB ackColor = System.Drawing. Color.AntiqueWh ite;
| > |
| > |
| > | DataGridTextBox Column cs2 = new DataGridTextBox Column();
| > |
| > | cs2.MappingName = "QuestionID ";
| > |
| > | cs2.HeaderText = "No.";
| > |
| > | cs2.Alignment = HorizontalAlign ment.Left;
| > |
| > | cs2.Width = 33;
| > |
| > | cs2.ReadOnly = true;
| > |
| > |
| > | gs.GridColumnSt yles.Add(cs2);
| > |
| > |
| > | DataGridBoolCol umn cs = new DataGridBoolCol umn(); // cs =
Column
| > | Style
| > |
| > | cs.MappingName = "Publish";
| > |
| > | cs.HeaderText = "Publish";
| > |
| > | cs.Width = 75;
| > |
| > | gs.GridColumnSt yles.Add(cs);
| > |
| > | cs = new DataGridBoolCol umn();
| > |
| > | cs.MappingName = "Required";
| > |
| > | cs.HeaderText = "Mandatory" ;
| > |
| > | cs.Width = 75;
| > |
| > | cs2.ReadOnly = true;
| > |
| > | gs.GridColumnSt yles.Add(cs);
| > |
| > | cs2 = new DataGridTextBox Column();
| > |
| > | cs2.MappingName = "QuestionTy pe";
| > |
| > | cs2.HeaderText = "Question Type";
| > |
| > | cs2.Alignment = HorizontalAlign ment.Center;
| > |
| > | cs2.Width = 80;
| > |
| > | cs2.ReadOnly = true;
| > |
| > | gs.GridColumnSt yles.Add(cs2);
| > |
| > | cs2 = new DataGridTextBox Column();
| > |
| > | cs2.MappingName = "Ask";
| > |
| > | cs2.HeaderText = "Question";
| > |
| > | cs2.Alignment = HorizontalAlign ment.Left;
| > |
| > | cs2.Width = 255;
| > |
| > | cs2.ReadOnly = true;
| > |
| > | gs.GridColumnSt yles.Add(cs2);
| > |
| > | dataGridQuestio ns.TableStyles. Add(gs);
| > |
| > |
| > | }
| > |
| > | panelDgQuestion s.Show();
| > |
| > | panelSplash.Hid e();
| > |
| > | }
| > |
| > |
| > |
| > | And then after that, they can delete a row from the datagrid. Then
this
| > | function is called
| > |
| > |
| > |
| > | /// <summary>
| > |
| > | /// this will remove the questions and then shuffle up all the
questions
| > | after it
| > |
| > | /// </summary>
| > |
| > | /// <param name="questionI D">question ID to remove</param>
| > |
| > | public void removeAndShuffl e(int questionID)
| > |
| > | {
| > |
| > | for(int i=0; i< this.myQuestion s.Count; i++)
| > |
| > | {
| > |
| > |
| if(((Learningfa st.QGM.Question )this.myQuestio ns[i]).QuestionID
| > | == questionID)
| > |
| > | {
| > |
| > | this.myQuestion s.RemoveAt(i);
| > |
| > | }
| > |
| > | }
| > |
| > | }
| > |
| > |
| > |
| > | In debug mode, for example if there were 2 rows, it is now 1 row and
| > | everything seems fine, but when i rebind the datagrid with the
arraylist
| > | after an object has been removed,
| > |
| > | private void BindQuestions()
| > |
| > | {
| > |
| > | dataGridQuestio ns.DataSource= this.AppQuiz.ge tQuestions();
| > |
| > | this.toolBarBtn Save.Enabled=tr ue;
| > |
| > | this.toolBarBtn Del.Enabled=tru e;
| > |
| > | }
| > |
| > | Mind you it does not run through the initializing statements of the
| > | datagrid, it just rebinds the datasource. And then at this point when | the
| > | datagrid is meant to be displayed, it gives me an error index [index
| > number
| > | that was deleted] is out of bounds.
| > |
| > | Can someone please tell me whats happening? I've read up in several
| cases
| > | and usually this means that I'm trying to bring up the object that was | > | deleted but I'm just changing the datasource to the amended arraylist. | > Could
| > | this have to do with my existing datagrid where i'm not initializing
it
| > | again? because I've tried that and it also brings up an error saying
| that
| > | i'm using the same "mapping name"
| > |
| > | Thanks in advance.
| > |
| > | Kind Regards
| > |
| > | Alex Ting
| > |
| > |
| > | ---
| > | Outgoing mail is certified Virus Free.
| > | Checked by AVG anti-virus system (http://www.grisoft.com).
| > | Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003
| > |
| > |
| > |
| >
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.536 / Virus Database: 331 - Release Date: 3/11/2003
|
|
|

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.542 / Virus Database: 336 - Release Date: 18/11/2003

Nov 15 '05 #1
1 4335

Hi Alex,

Just as my origianl suggestion, do you decrease CurrencyManager .Position
property?
I think you should download a full sample about the arraylist sample at:
http://www.syncfusion.com/faq/winfor...darraylist.zip
It tells you exactly, how do you add and remove a item from arraylist, then
reflect this well into the datagrid.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2

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

Similar topics

4
3898
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I think my logic seems fine but when I click the button on my datagrid nothing seems to happen. Have you any idea where Im going wrong. Was thinking it might have something to do with my page load/ postback but not really sure. Can someone please...
7
3984
by: Jerry S | last post by:
Hi I've got an arraylist of integers. I want to be able to remove an integer from the list using a method like this: public void ArrayListRemove(int indexnum) { ArrayList.Remove(ArrayList.IndexOf(indexnum));
7
455
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a arrayList to the datagrid. private void BindQuestions()
7
14258
by: William Stacey [MVP] | last post by:
I can think of a couple ways to do this, but was wonder what the fastest way you can think of. Want to take any arraylist of > 1 element and make the first element the last, and all the rest of the elements will move up one position. This will be called a lot, so looking for speed. This just saving the index 0 as tmp and then enum the list to move up the elements, then put the tmp object in last pos is the best way? Cheers --...
3
3752
by: JJ | last post by:
Hi, I have created an Arraylist object from an Arraylist class. I added rows to the arraylist object and I need to find a particular record in my arraylist. How do I do this? Also if I was in the middle of building the arraylist and wanted to call the last record added to arraylist object how can I do this? Thanks,
5
4499
by: nadeem_far | last post by:
Hello All, I have been trying to solve the following issue and it seems like there is no solution available any where and maybe people at Microsoft should may be of some help. I am writing a .Net desktop application using C# and framework version 1.1 I have a arraylist of some objects of the same type and I am showing
20
5970
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim mylist as new FrameList mylist.Add(new FrameStructure) mylist(0).first = "blabla..." mylist(0).second...
31
4583
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there are more objects that match the first object that i grabbed. If they match then I put them in an array. I would like to remove each match from the arraylist as I find them to speed things up and so that they don't get checked again. If I try...
7
2633
by: David Lozzi | last post by:
Howdy, I have a shopping cart in my arraylist. Works great for adding items but I'm displaying the shopping cart in a gridview and the user can update the qty of the items. If they set it to 0, then I want to remove it. I'm doing the following script: For Each ele In bag Dim qty As Integer = CType(gvBag.Rows.Item(cnt).FindControl("txtQty"),
6
3135
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it to the client. Before adding data to the arraylist, I check if the depth of the arraylist is longer than iMaxQueueDepth, and if it is, I clear the arraylist. Is it possible that while I am clearing the arraylist, the ThreadMain at the same time...
0
8481
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
8400
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
8924
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
8823
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
8602
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
5702
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
4227
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...
1
2817
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
2
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.