App. crashes on assigning arraylist to DataGridView datasource

W

weird0

I am assigning an arrlist to the datasource property of the
datagridview. In short, i want to update the datagridview. But the
moment, i assign it. The application crashes. It does not display the
updated state of the datagridview neither throws any exception. Here
is some of the following code:

public void AddState(string stateName,float Prob) // Add a
new state, to the arrlist
{
StateTable newState = new StateTable();
newState.State = stateName;
newState.Probability = Prob;
statesList.Add(newState);
}

private void button3_Click(object sender, EventArgs e)
{
try
{
int rows = dataGridView1.Rows.Count;
rows--;
n1.AddState("State" + rows.ToString(), 0); // Add a
state to the node
dataGridView1.DataSource = n1.statesList;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

Please help
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

weird0 said:
I am assigning an arrlist to the datasource property of the
datagridview. In short, i want to update the datagridview. But the
moment, i assign it. The application crashes. It does not display the
updated state of the datagridview neither throws any exception. Here
is some of the following code:

public void AddState(string stateName,float Prob) // Add a
new state, to the arrlist
{
StateTable newState = new StateTable();
newState.State = stateName;
newState.Probability = Prob;
statesList.Add(newState);
}

private void button3_Click(object sender, EventArgs e)
{
try
{
int rows = dataGridView1.Rows.Count;
rows--;
n1.AddState("State" + rows.ToString(), 0); // Add a
state to the node
dataGridView1.DataSource = n1.statesList;

Reassigning the same object as data source has no effect at all.
Therefore you are changing the contents of the data source under the
feet of the data grid, without even telling it.

Try to remove the data source before changing it (setting DataSource to
null), then reassigning it afterwards.
 

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