473,324 Members | 2,268 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,324 software developers and data experts.

ArrayList.RemoveAt(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.microsoft.com> wrote in message
news:Y8**************@cpmsftngxa06.phx.gbl...

Hi Alex,

You should set DataGridTableStyle's MappingName to "ArrayList", then set
DataGridColumnStyle's MappingName to Arraylist's public property.
When deleting the arraylist member, you should refer to the
CurrencyManager(Manages the collection of BindingManagerBase 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***@learningfast.com>
| References: <Oa*************@TK2MSFTNGP11.phx.gbl>
<Mh**************@cpmsftngxa06.phx.gbl>
| Subject: Re: ArrayList.RemoveAt(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.public.dotnet.languages.csharp
| NNTP-Posting-Host: learningfast2.learnfast.monash.edu.au 130.194.247.2
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:197066 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Jeff,
|
| Thanks for your reply.
|
| the getQuestions simply returns the arrayList
|
| public Learningfast.QGM.QuizList getQuestions()
|
| {
|
| return this.myQuestions;
|
| }
|
| 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.microsoft.com> wrote in message
| news:Mh**************@cpmsftngxa06.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(WinForm).
| > 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***@learningfast.com>
| > | Subject: ArrayList.RemoveAt(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.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: learningfast2.learnfast.monash.edu.au 130.194.247.2 | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:195620
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.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()
| > |
| > | {
| > |
| > | dataGridQuestions.DataSource= this.AppQuiz.getQuestions();
| > |
| > | this.toolBarBtnSave.Enabled=true;
| > |
| > | this.toolBarBtnDel.Enabled=true;
| > |
| > | }
| > |
| > |
| > |
| > | public void loadQuestions()
| > |
| > | {
| > |
| > | this.BindQuestions();//this.AppQuiz.getQuestions();//AppQuiz();
| > |
| > | if(this.DataGridSet==false)
| > |
| > | {
| > |
| > | DataGridTableStyle gs = new DataGridTableStyle(); // gs = Grid | > Style
| > |
| > |
| > | gs.MappingName = AppQuiz.getQuestions().GetType().Name;
| > | //dummyDataArr.GetType().Name;
| > |
| > | gs.AllowSorting = true;
| > |
| > | gs.AlternatingBackColor = System.Drawing.Color.AntiqueWhite;
| > |
| > |
| > | DataGridTextBoxColumn cs2 = new DataGridTextBoxColumn();
| > |
| > | cs2.MappingName = "QuestionID";
| > |
| > | cs2.HeaderText = "No.";
| > |
| > | cs2.Alignment = HorizontalAlignment.Left;
| > |
| > | cs2.Width = 33;
| > |
| > | cs2.ReadOnly = true;
| > |
| > |
| > | gs.GridColumnStyles.Add(cs2);
| > |
| > |
| > | DataGridBoolColumn cs = new DataGridBoolColumn(); // cs =
Column
| > | Style
| > |
| > | cs.MappingName = "Publish";
| > |
| > | cs.HeaderText = "Publish";
| > |
| > | cs.Width = 75;
| > |
| > | gs.GridColumnStyles.Add(cs);
| > |
| > | cs = new DataGridBoolColumn();
| > |
| > | cs.MappingName = "Required";
| > |
| > | cs.HeaderText = "Mandatory";
| > |
| > | cs.Width = 75;
| > |
| > | cs2.ReadOnly = true;
| > |
| > | gs.GridColumnStyles.Add(cs);
| > |
| > | cs2 = new DataGridTextBoxColumn();
| > |
| > | cs2.MappingName = "QuestionType";
| > |
| > | cs2.HeaderText = "Question Type";
| > |
| > | cs2.Alignment = HorizontalAlignment.Center;
| > |
| > | cs2.Width = 80;
| > |
| > | cs2.ReadOnly = true;
| > |
| > | gs.GridColumnStyles.Add(cs2);
| > |
| > | cs2 = new DataGridTextBoxColumn();
| > |
| > | cs2.MappingName = "Ask";
| > |
| > | cs2.HeaderText = "Question";
| > |
| > | cs2.Alignment = HorizontalAlignment.Left;
| > |
| > | cs2.Width = 255;
| > |
| > | cs2.ReadOnly = true;
| > |
| > | gs.GridColumnStyles.Add(cs2);
| > |
| > | dataGridQuestions.TableStyles.Add(gs);
| > |
| > |
| > | }
| > |
| > | panelDgQuestions.Show();
| > |
| > | panelSplash.Hide();
| > |
| > | }
| > |
| > |
| > |
| > | 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="questionID">question ID to remove</param>
| > |
| > | public void removeAndShuffle(int questionID)
| > |
| > | {
| > |
| > | for(int i=0; i< this.myQuestions.Count; i++)
| > |
| > | {
| > |
| > |
| if(((Learningfast.QGM.Question)this.myQuestions[i]).QuestionID
| > | == questionID)
| > |
| > | {
| > |
| > | this.myQuestions.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()
| > |
| > | {
| > |
| > | dataGridQuestions.DataSource= this.AppQuiz.getQuestions();
| > |
| > | this.toolBarBtnSave.Enabled=true;
| > |
| > | this.toolBarBtnDel.Enabled=true;
| > |
| > | }
| > |
| > | 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 4298

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
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...
7
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) {...
7
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...
7
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...
3
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...
5
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...
20
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...
31
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...
7
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,...
6
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...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.