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
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
Comment