views:

38

answers:

1

I've a datatable bound to a gridview.

The datatable has the following data:

JobID   Site Job List
---------   --------- --------- ---------
134 A job1 26
2241    A job2 25
124 A job3 26
244 B job1 12
154 B ads2 46

Am trying to take the count of distinct sites. So I write the following function:

    public void CreateAdmins(DataTable JobsToStart)
    {
        DataView uniqueDialers = new DataView(JobsToStart);
        uniqueDialers = uniqueDialers.ToTable(true, "Site").DefaultView;
        Debug.Print(uniqueDialers.Rows.Count);
    }

After executing the above function the data which is displayed in the datagridview changes. How do I avoid this?

A: 

If I understand your question correctly...

Assign it to a different variable. The datagrid is looking at the same object that you are later modifying using this function. This is because it has been 'passed by reference'. Have a look at this article for info on that.

Fiona Holder
Show me some code plz. My assumption was you'd get an independent view if you call its constructor with a datatable...
deostroll
When you say "the data which is displayed in the datagridview changes" - do you mean that the function above modifies the data grid when you don't want it to?
Fiona Holder