tags:

views:

65

answers:

4

Here comes the trouble. I want to delete all rows from datagridview. This how i add rows:

private void ReadCompleteCallback(object clientHandle, Opc.Da.ItemValueResult[]     results)
    {
        foreach (Opc.Da.ItemValueResult readResult in results)
        {
            dataGridView1.Invoke(new MethodInvoker(() => dataGridView1.Rows.Add(readResult.ItemName, readResult.Quality, readResult.Timestamp,readResult.Value)));        
        }
    }

And its how i clear gridview:

private void treeView1_SelectionsChanged(object sender, EventArgs e) {

        dataGridView1.Rows.Clear();
        items = new Opc.Da.Item[treeView1.SelectedNodes.Count]; 
        foreach (TreeNode x in treeView1.SelectedNodes) {
            items[treeView1.SelectedNodes.IndexOf(x)] = new Opc.Da.Item();
            items[treeView1.SelectedNodes.IndexOf(x)].ItemName = x.Text; 
        }


        group.AddItems(items);
        group.Read(group.Items, 123, new Opc.Da.ReadCompleteEventHandler(ReadCompleteCallback), out req);
    }

in debug i see that dataGridVIew1.Rows.Count=0, but on form, grid doesnt become clear. what a point? on each selection in tree, i want to see new rows in table.

A: 

try setting RowCount to 0(allowuserstorows should be false), along with calling clear

Vinay B R
it says that number of rows must be at least 1. but even setting it to 1 - doesnt help.
eba
A: 

I'm betting you just need to refresh the datagrid. Try this:

dataGridView1.Rows.Clear();
dataGridView1.Refresh();

If this works... you might want to rethink this part of your application.

NitroxDM
thx. but i've tried this. refresh and update. doesnt help
eba
A: 

thx to all. trouble not in datagridview. its my fault with opc server subscribing group, i didnt clear variables in there.

eba
A: 

If I remember correctly, I set the DataSource property to null to clear the DataGridView.

dboarman