By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

ArrayList.RemoveAt(i)

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.