ArrayList.RemoveAt(i)

A

Alex Ting

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).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
 
J

Jeffrey Tan[MSFT]

Hi Alex,

I have reviewed your post, I will do some research for you.
I will reply to you after I research it out.
Thanks for your understanding.

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" <[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP11.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).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
|
|
|
 
A

Alex Ting

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]" said:
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/WinForms/FAQ_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" <[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP11.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).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
|
|
|
 
J

Jeffrey Tan[MSFT]

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" <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP10.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
|
|
| | >
| > 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/WinForms/FAQ_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" <[email protected]>
| > | 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: <[email protected]>
| > | 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!TK2MSFTNGP11.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).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
|
|
|
 
A

Alex Ting

Hi Jeffrey,

Thanks for that!

Such as simple solution...
just set the databindings to null and then bind it to the arraylist straight
after!
Kind Regards
Alex
"Jeffrey Tan[MSFT]" said:
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" <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP10.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
|
|
| | >
| > 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/WinForms/FAQ_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" <[email protected]>
| > | 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: <[email protected]>
| > | 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!TK2MSFTNGP11.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).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
|
|
|
 
J

Jeffrey Tan[MSFT]

Hi Alex,

I am glad it works.
If you still have any question, 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" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: ArrayList.RemoveAt(i)
| Date: Fri, 7 Nov 2003 09:50:17 +1100
| Lines: 362
| 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: <[email protected]>
| 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!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:197317
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Jeffrey,
|
| Thanks for that!
|
| Such as simple solution...
| just set the databindings to null and then bind it to the arraylist
straight
| after!
| Kind Regards
| Alex
| | >
| > 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" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | 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: <[email protected]>
| > | 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!TK2MSFTNGP10.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
| > |
| > |
| > | | > | >
| > | > 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/WinForms/FAQ_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" <[email protected]>
| > | > | 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: <[email protected]>
| > | > | 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!TK2MSFTNGP11.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).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.536 / Virus Database: 331 - Release Date: 4/11/2003
|
|
|
 
A

Alex Ting

Hi Jeff,

I've done the same things for another array list like resetting the
datasource but this time 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 you have any ideas?

Thanks in advance

Alex Ting

"Jeffrey Tan[MSFT]" said:
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" <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP10.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
|
|
| | >
| > 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/WinForms/FAQ_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" <[email protected]>
| > | 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: <[email protected]>
| > | 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!TK2MSFTNGP11.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).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
|
|
|
 
J

Jeffrey Tan[MSFT]

Hi Alex,

I have viewed your follow up problem, and I also found that you have posted
a new post for this issue.
I have replied you in that post. Please follow up there, I will work with
you.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top