user1869914
user1869914

Reputation: 51

Dataview Table.Rows.Count is returning 1 when there is no such rows

consider the code below:

DataView deletedLOV = new DataView(tbltmp, "prociLOV_Deleted=1", "prociLOV_ID",
                                   DataViewRowState.CurrentRows);
DataView addedLOV = new DataView(tbltmp, "prociLOV_Id>1", "prociLOV_ID",
                                 DataViewRowState.CurrentRows);
int deletedLOVcount=deletedLOV.Table.Rows.Count;
int addedLOVcount=addedLOV.Table.Rows.Count;

prociLOV_Deleted is set to 1 when a record is deleted.

But even when no records are deleted the deletedLOVcount return value 1. Also the same with addedLOVcount when there is no record with proci_ID>1 ,it too returns count as1

Upvotes: 4

Views: 10728

Answers (2)

beg-inner
beg-inner

Reputation: 5

Having a DataView with different filters on it and made simple test with a ContextMexuStrip that reflects by simply right click the amount of DataView.Count exactly by choosen filter. So I confirm this is the right pick that represents available rows in the View after a filter is applied to all available rows in the view.

example code:

DataGridView myDGV = new DataGridView();
... ( set up your dgv )
DataView myDV = new DataView();
... ( add handlers if you need )
DataTable myDT = new DataTable(myDV);
myDGV.BindSource = myDT;

By adding to a contextmenustrip myCMS.Item.Add(" available entries : " + myDV.Count() ); you have it reflected.

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460158

The DataView references it's original DataTable via the Table property. But it does not share the same data. The DataTable contains the original data without the applied filter whereas the DataView contains only the records after the appplied filter.

You would get the correct count via DataView.Count:

int deletedLOVcount = deletedLOV.Count;

MSDN:

Gets the number of records in the DataView after RowFilter and RowStateFilter have been applied.

Upvotes: 7

Related Questions