Currency Manager

H

Hemang Shah

Currencymanger is a boon, but making it work in out of the box situation
could be challenging.

Is there any sample or article, which describes, how to synchronize two
dataviews bound to the same data table?

This is the scenario:

dvDataView1 is bound to Dataset.DataTable.
dvDataView2 is bound to DataSet.DataTable.

Both dataview 1 & 2 are bound ot the same datatable in the same dataset.

But both of these have their own currency manager (am I right here?)

What I need is, even after filtering & sorting on dvDataView2, when a record
is selected, the currencymanager 's position on dvDataView1 should be
updated.

How can I do this?......... I've searched a lot online, can't seem to find
an answer.

Thanks
 
C

Cor Ligthert [MVP]

Hemang,
But both of these have their own currency manager (am I right here?)
No.

Only if you create "new" dataviews. Otherwise they point to everything the
same. In fact it are the defaultviews of the tables.

In other words, all your controls binded to the same dataview or reference
to that will have the same row as the currentrow

This kind of things is easy to try by the way.

Cor
 
H

Hemang Shah

Robin, Yes its the same issue, I posted it under a more meaningful heading,
Thanks

Cor,

Maybe I was not clear in what I said.

There are "two" different dataviews (not just one referencing the other)

The reason I need two different dataview is because, all the controls on the
form are bound to the first dataview.

I want to display a datagrid which the user can filter by some criteria, If
I use the same dataview for this then the records on the main form are
filtered too. I dont want that. I want only the datagrid to be filtered.
So I created another dataview, which works fine, because now the filtering
of this second dataview does not affect the main form as its bound to the
first dataview.

Where I'm stuck is that, once the user selects a record in the datagrid
which is bound to the second dataview, I want that particular record to be
displayed in the main form which is bound to the first dataview.

and Cor, I did try this on the form, if I bound both the form & datagrid to
the same dataview (or a reference to it), you are right, the
currencymanager.position is in sync. and selecting one record, selects the
same in the other. But filtering one also filters the other, which I don't
want and so I tried with a second dataview, which can be filtered
independantly but now is not in sync. The only way its not in sync is
because it would have its own currencymanager isn't it?

Thanks
 
C

Cor Ligthert [MVP]

Hemang,

I don't see the "New" keyword in your messages.

dv as dataview = myoldDataview
this is just a reference
dvnieuw as New dataview(MyTable)
this is a new dataview with its own currencymanager.

Cor
 
H

Hemang Shah

Cor,

I'm not asking how to create a new dataview.

I've already done that.

I want to sync the currencymanagers of the two dataview.

Thanks
 
C

Cor Ligthert [MVP]

Show us than how you build those.

Cor

Hemang Shah said:
Cor,

I'm not asking how to create a new dataview.

I've already done that.

I want to sync the currencymanagers of the two dataview.

Thanks
 
H

Hemang Shah

In the GUI, I made a copy of dvClient (my original dataview), here is the
code that VS generated: I'll paste in code for the second dataview.

public System.Data.DataView dvClient; (the original dataview bound to the
main form)

public DataView dvForSearch; (the new dataview I created for the datagrid)

this.dvForSearch = new System.Data.DataView();

((System.ComponentModel.ISupportInitialize)(this.dvForSearch)).BeginInit();

//

// dvForSearch

//

this.dvForSearch.Sort = "GivenName";

this.dvForSearch.Table = this.dsClient.tblClient;



this.dataGridView1.DataSource = this.dvForSearch;

((System.ComponentModel.ISupportInitialize)(this.dvForSearch)).EndInit();
 
C

Cor Ligthert [MVP]

Hemang,

Can you try this piece of code with 3 datagridviews on the fomr

private void Form1_Load(object sender, EventArgs e)
{
DataTable DT = new DataTable();
DataColumn DC1 = new DataColumn("One");
DataColumn DC2 = new DataColumn("Two");
DT.Columns.Add(DC1);
DT.Columns.Add(DC2);
DT.LoadDataRow(new object[] {"Hemang","Shah"},true);
DT.LoadDataRow(new object[] {"Cor","Ligthert"},true);
DataView DV1 = new DataView(DT);
DataView DV2 = new DataView(DT);
DataView DV3 = DV1;
DV1.Sort = "One Desc";
DV2.Sort = "One Asc";
DV3.Sort = "One Asc";
dataGridView1.DataSource = DV1;
dataGridView2.DataSource = DV2;
dataGridView3.DataSource = DV3;
}

Cor
 

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