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