开发者

why does datagridview disappear after refreshing twice?

on form load, my datagridview display a datatable. once the user clicks the delete button, it deletes one of the rows in the data source:

private void btnDelete_Click(object sender, EventArgs e)
        {
            Int32 selectedRowCount =
        dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
            if (selectedRowCount == 1)
            {


                    qResults.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
                    chart1.DataSource = qResults;
                    InitializeChart();

                    dataGridView1.Columns.Clear();
                    dataGridView1.DataBindings.Clear();
                    dataGridView1.DataSource = qResults;


            }
        }

the first time i click this button, it works. it deletes the datapoint from the source and refreshes the chart. however, the second time i click it, it completely wipes out the datagridview and display NOTHING. but please note that the chart displays correctly

anyone know wh开发者_StackOverflow社区at am i donig wrong?


Have you tried commenting out the chart code entirely and seeing if your datagridview still shows the same behavior?

Also: what is qResults? The type isn't clear here. If you use a data source like BindingSource, you may not need to reset the datagridview's data source and clear its bindings and columns; the BindingSource with the datagridview takes care of that for you.

If qResults is a DataTable, try using a BindingSource. Set the DataTable as the BindingSource's data source, then set the BindingSource as the datagridview's data source, then see what happens with your delete.

Lastly, do you have explicit databinding code somewhere or do you have datagridview column auto-generate on?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜