|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
copying an object by valueHere is the scenario: Main Form - which calls a Search form. - I pass Mainform as a reference so that I can pass data between the two. Code: public frmSearch(Form1 f) { InitializeComponent(); frmMain = new Form1(); frmMain = f; dvSearch = new System.Data.DataView(); dvSearch = frmMain.dvClient; this.BindingContext = frmMain.BindingContext; dgvSearchDisplay.DataSource = dvSearch; } I have a dataView on the main form called (dvClient) I have a datagrid on the SearchForm which I want to filter / sort without affecting the main form. So I create a copy of the dataview from main form into a dataview called dvSearch. But now when I apply a row filter to this dvSearch, the main form is getting affected to. The reason why making a copy of the dataview is important because I want to retain the currencymanager value. So that once a record is selected in the datagrid in the searchform, the fields are updated on the main form. Hope this explains what I'm trying to achieve. Thanks "Hemang Shah" <hem***@hemang.net> wrote in message Notice that the first one of these two lines is superfluous, since the news:ehyt6DWeHHA.4172@TK2MSFTNGP05.phx.gbl... > [...] > frmMain = new Form1(); > frmMain = f; frmMain that you initialized with the "new" gets immediately overwritten wit "f". > dvSearch = new System.Data.DataView(); Same thing here. The first "new" is useless, since the second line > dvSearch = frmMain.dvClient; overwrites dvSearch with a new value. > [...] No, the previous line does not copy the dataview. It only copies the > So I create a copy of the dataview from main form into a dataview called > dvSearch. reference to the dataview. Both frmMain.dvClient and dvSearch still point to the same dataview. > But now when I apply a row filter to this dvSearch, the main form is Yes, because dvSearch points to the same dataview that frmMain has, so > getting affected to. changing one of its properties affects frmMain. > The reason why making a copy of the dataview is important because I want You will need to rethink it a little bit. You can create a second > to retain the currencymanager value. > > So that once a record is selected in the datagrid in the searchform, the > fields are updated on the main form. > > Hope this explains what I'm trying to achieve. dataview from the same datatable from which you created the first one: dvSearch = new System.Data.DataView(frmMain.dvClient.Table); But this does not relate the second dataview to the currencymanager, so you will have to elaborate your code a little more. Thanks for the reply Alberto
I got that far. Yours is a bit better than my idea, but what I did is: On the main form, I created another dataview pointing to the same table in the same dataset and I was sending that to the child form. But the problem is, Now when a user clicks on an item in the child form, the main form doesn't point to that record (because the currencymanagers are different). I've been searching high & low on how to sync two dataview bound to the same datatable. I can't find anyways of doing it. I can't even think how to do it manually if currencymanager is not working out. any advice? Thanks Show quoteHide quote "Alberto Poblacion" <earthling-quitaestoparacontes***@poblacion.org> wrote in message news:eHcKzFbeHHA.4868@TK2MSFTNGP06.phx.gbl... > "Hemang Shah" <hem***@hemang.net> wrote in message > news:ehyt6DWeHHA.4172@TK2MSFTNGP05.phx.gbl... >> [...] >> frmMain = new Form1(); >> frmMain = f; > > Notice that the first one of these two lines is superfluous, since the > frmMain that you initialized with the "new" gets immediately overwritten > wit "f". > >> dvSearch = new System.Data.DataView(); >> dvSearch = frmMain.dvClient; > > Same thing here. The first "new" is useless, since the second line > overwrites dvSearch with a new value. > >> [...] >> So I create a copy of the dataview from main form into a dataview called >> dvSearch. > > No, the previous line does not copy the dataview. It only copies the > reference to the dataview. Both frmMain.dvClient and dvSearch still point > to the same dataview. > >> But now when I apply a row filter to this dvSearch, the main form is >> getting affected to. > > Yes, because dvSearch points to the same dataview that frmMain has, so > changing one of its properties affects frmMain. > >> The reason why making a copy of the dataview is important because I want >> to retain the currencymanager value. >> >> So that once a record is selected in the datagrid in the searchform, the >> fields are updated on the main form. >> >> Hope this explains what I'm trying to achieve. > > You will need to rethink it a little bit. You can create a second > dataview from the same datatable from which you created the first one: > dvSearch = new System.Data.DataView(frmMain.dvClient.Table); > But this does not relate the second dataview to the currencymanager, > so you will have to elaborate your code a little more. > > On Apr 8, 9:49 am, "Hemang Shah" <hem***@hemang.net> wrote: First, a caveat: I've never used datagrids or currencymanagers.> Thanks for the reply Alberto > > I got that far. Yours is a bit better than my idea, but what I did is: > > On the main form, I created another dataview pointing to the same table in > the same dataset and I was sending that to the child form. > > But the problem is, Now when a user clicks on an item in the child form, the > main form doesn't point to that record (because the currencymanagers are > different). However, I have done the sort of thing you're trying to do in other situations. There are two possibilities (and you haven't really defined which one you're trying to achieve): 1) you want the main form to update as soon as the user clicks an item on the search form; 2) you want the main form to update as soon as the user clicks and item on the search form and dismisses it. In other words, is the search form running in parallel with the main form (searchForm.Show()) or is it a dialog (searchForm.ShowDialog())? In the first case, the solution is this: define an event on your search form: public event System.EventHandler UserSelectedItem; and a property: public XXX SelectedItem { get { ... } } Have your main form subscribe to the event. Whenever the event is raised, the main form will read the SelectedItem property, find the same item in its grid, and select it. On the other hand, if your search form is a dialog, you don't need the event, just the property. When the dialog returns, if the user clicked OK, the main form just reads the SelectedItem property and sets its current item accordingly. Thanks Bruce
Either option will work for me. Eventually when the user exists the Searchform, I want the required record to show on the main form, if it shows even before the searchform is closed, it doesn't matter. All that matters is once the user selects a record in the datagrid on the search form, and clicks ok (to close it), the main form displays that record. My Search Form is a .showDialog(), as I don't want them to do data entry when the search form is still open. Secondly, the main form doesn't use datagrid, it is the search form which uses the datagrid to select the record. The main form has multiple text boxes, combo boxes, lists...( a typical data entry form). All the controls are bound to a dataview. I don't know how to select a particular record in a dataview. Because you cannot use find on a dataview unless the column in the dataview is sorted. Which is not the case in mine. Show quoteHide quote "Bruce Wood" <brucew***@canada.com> wrote in message news:1176055379.707713.3380@o5g2000hsb.googlegroups.com... > On Apr 8, 9:49 am, "Hemang Shah" <hem***@hemang.net> wrote: >> Thanks for the reply Alberto >> >> I got that far. Yours is a bit better than my idea, but what I did is: >> >> On the main form, I created another dataview pointing to the same table >> in >> the same dataset and I was sending that to the child form. >> >> But the problem is, Now when a user clicks on an item in the child form, >> the >> main form doesn't point to that record (because the currencymanagers are >> different). > > First, a caveat: I've never used datagrids or currencymanagers. > However, I have done the sort of thing you're trying to do in other > situations. > > There are two possibilities (and you haven't really defined which one > you're trying to achieve): 1) you want the main form to update as soon > as the user clicks an item on the search form; 2) you want the main > form to update as soon as the user clicks and item on the search form > and dismisses it. > > In other words, is the search form running in parallel with the main > form (searchForm.Show()) or is it a dialog (searchForm.ShowDialog())? > > In the first case, the solution is this: define an event on your > search form: > > public event System.EventHandler UserSelectedItem; > > and a property: > > public XXX SelectedItem { get { ... } } > > Have your main form subscribe to the event. Whenever the event is > raised, the main form will read the SelectedItem property, find the > same item in its grid, and select it. > > On the other hand, if your search form is a dialog, you don't need the > event, just the property. When the dialog returns, if the user clicked > OK, the main form just reads the SelectedItem property and sets its > current item accordingly. > Hemang,
You are stating so many things which are untrue, that it is almost impossible to answer. However to answer one, there are 4 methods to find a row in a dataview. The easiest one is to use the rowfilter. Cor Show quoteHide quote "Hemang Shah" <hem***@hemang.net> schreef in bericht news:%23betvzheHHA.3960@TK2MSFTNGP02.phx.gbl... > Thanks Bruce > > Either option will work for me. Eventually when the user exists the > Searchform, I want the required record to show on the main form, if it > shows even before the searchform is closed, it doesn't matter. All that > matters is once the user selects a record in the datagrid on the search > form, and clicks ok (to close it), the main form displays that record. > > My Search Form is a .showDialog(), as I don't want them to do data entry > when the search form is still open. > > Secondly, the main form doesn't use datagrid, it is the search form which > uses the datagrid to select the record. > > The main form has multiple text boxes, combo boxes, lists...( a typical > data entry form). > > All the controls are bound to a dataview. > > I don't know how to select a particular record in a dataview. > > Because you cannot use find on a dataview unless the column in the > dataview is sorted. Which is not the case in mine. > > > "Bruce Wood" <brucew***@canada.com> wrote in message > news:1176055379.707713.3380@o5g2000hsb.googlegroups.com... >> On Apr 8, 9:49 am, "Hemang Shah" <hem***@hemang.net> wrote: >>> Thanks for the reply Alberto >>> >>> I got that far. Yours is a bit better than my idea, but what I did is: >>> >>> On the main form, I created another dataview pointing to the same table >>> in >>> the same dataset and I was sending that to the child form. >>> >>> But the problem is, Now when a user clicks on an item in the child form, >>> the >>> main form doesn't point to that record (because the currencymanagers are >>> different). >> >> First, a caveat: I've never used datagrids or currencymanagers. >> However, I have done the sort of thing you're trying to do in other >> situations. >> >> There are two possibilities (and you haven't really defined which one >> you're trying to achieve): 1) you want the main form to update as soon >> as the user clicks an item on the search form; 2) you want the main >> form to update as soon as the user clicks and item on the search form >> and dismisses it. >> >> In other words, is the search form running in parallel with the main >> form (searchForm.Show()) or is it a dialog (searchForm.ShowDialog())? >> >> In the first case, the solution is this: define an event on your >> search form: >> >> public event System.EventHandler UserSelectedItem; >> >> and a property: >> >> public XXX SelectedItem { get { ... } } >> >> Have your main form subscribe to the event. Whenever the event is >> raised, the main form will read the SelectedItem property, find the >> same item in its grid, and select it. >> >> On the other hand, if your search form is a dialog, you don't need the >> event, just the property. When the dialog returns, if the user clicked >> OK, the main form just reads the SelectedItem property and sets its >> current item accordingly. >> > > Cor,
Please correct me what i'm wrong about, so that I can learn. I'm curious, you mention finding by using the rowfilter.. isn't searching & filtering different ? I'm using RowFilter to filter the datagrid, here is the code: dvSearch.RowFilter = "GivenName LIKE '" +txtSearchFirstName.Text.Replace("'","''") + "%'"; dgvSearchDisplay.Refresh(); But what I want is the record selected in this datagrid, to be displayed on the main form, which is bound by a different dataview (but point to the same data table). My question is, how can we sync two different currencymanagers? I'm no guru, just getting my hands dirty with some ado.net code (which is obvious in my basic questions) Thanks Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:Org9HejeHHA.4564@TK2MSFTNGP03.phx.gbl... > Hemang, > > You are stating so many things which are untrue, that it is almost > impossible to answer. > > However to answer one, there are 4 methods to find a row in a dataview. > The easiest one is to use the rowfilter. > > Cor > > "Hemang Shah" <hem***@hemang.net> schreef in bericht > news:%23betvzheHHA.3960@TK2MSFTNGP02.phx.gbl... >> Thanks Bruce >> >> Either option will work for me. Eventually when the user exists the >> Searchform, I want the required record to show on the main form, if it >> shows even before the searchform is closed, it doesn't matter. All that >> matters is once the user selects a record in the datagrid on the search >> form, and clicks ok (to close it), the main form displays that record. >> >> My Search Form is a .showDialog(), as I don't want them to do data entry >> when the search form is still open. >> >> Secondly, the main form doesn't use datagrid, it is the search form which >> uses the datagrid to select the record. >> >> The main form has multiple text boxes, combo boxes, lists...( a typical >> data entry form). >> >> All the controls are bound to a dataview. >> >> I don't know how to select a particular record in a dataview. >> >> Because you cannot use find on a dataview unless the column in the >> dataview is sorted. Which is not the case in mine. >> >> >> "Bruce Wood" <brucew***@canada.com> wrote in message >> news:1176055379.707713.3380@o5g2000hsb.googlegroups.com... >>> On Apr 8, 9:49 am, "Hemang Shah" <hem***@hemang.net> wrote: >>>> Thanks for the reply Alberto >>>> >>>> I got that far. Yours is a bit better than my idea, but what I did is: >>>> >>>> On the main form, I created another dataview pointing to the same table >>>> in >>>> the same dataset and I was sending that to the child form. >>>> >>>> But the problem is, Now when a user clicks on an item in the child >>>> form, the >>>> main form doesn't point to that record (because the currencymanagers >>>> are >>>> different). >>> >>> First, a caveat: I've never used datagrids or currencymanagers. >>> However, I have done the sort of thing you're trying to do in other >>> situations. >>> >>> There are two possibilities (and you haven't really defined which one >>> you're trying to achieve): 1) you want the main form to update as soon >>> as the user clicks an item on the search form; 2) you want the main >>> form to update as soon as the user clicks and item on the search form >>> and dismisses it. >>> >>> In other words, is the search form running in parallel with the main >>> form (searchForm.Show()) or is it a dialog (searchForm.ShowDialog())? >>> >>> In the first case, the solution is this: define an event on your >>> search form: >>> >>> public event System.EventHandler UserSelectedItem; >>> >>> and a property: >>> >>> public XXX SelectedItem { get { ... } } >>> >>> Have your main form subscribe to the event. Whenever the event is >>> raised, the main form will read the SelectedItem property, find the >>> same item in its grid, and select it. >>> >>> On the other hand, if your search form is a dialog, you don't need the >>> event, just the property. When the dialog returns, if the user clicked >>> OK, the main form just reads the SelectedItem property and sets its >>> current item accordingly. >>> >> >> > > See my other answer
Show quoteHide quote "Hemang Shah" <hem***@hemang.net> schreef in bericht news:e0AIgrjeHHA.5044@TK2MSFTNGP06.phx.gbl... > Cor, > > Please correct me what i'm wrong about, so that I can learn. > > I'm curious, you mention finding by using the rowfilter.. > > isn't searching & filtering different ? > > I'm using RowFilter to filter the datagrid, here is the code: > > dvSearch.RowFilter = "GivenName LIKE '" > +txtSearchFirstName.Text.Replace("'","''") + "%'"; > > dgvSearchDisplay.Refresh(); > > But what I want is the record selected in this datagrid, to be displayed > on the main form, which is bound by a different dataview (but point to the > same data table). > > > > My question is, how can we sync two different currencymanagers? > > I'm no guru, just getting my hands dirty with some ado.net code (which is > obvious in my basic questions) > > Thanks > > > > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message > news:Org9HejeHHA.4564@TK2MSFTNGP03.phx.gbl... >> Hemang, >> >> You are stating so many things which are untrue, that it is almost >> impossible to answer. >> >> However to answer one, there are 4 methods to find a row in a dataview. >> The easiest one is to use the rowfilter. >> >> Cor >> >> "Hemang Shah" <hem***@hemang.net> schreef in bericht >> news:%23betvzheHHA.3960@TK2MSFTNGP02.phx.gbl... >>> Thanks Bruce >>> >>> Either option will work for me. Eventually when the user exists the >>> Searchform, I want the required record to show on the main form, if it >>> shows even before the searchform is closed, it doesn't matter. All that >>> matters is once the user selects a record in the datagrid on the search >>> form, and clicks ok (to close it), the main form displays that record. >>> >>> My Search Form is a .showDialog(), as I don't want them to do data entry >>> when the search form is still open. >>> >>> Secondly, the main form doesn't use datagrid, it is the search form >>> which uses the datagrid to select the record. >>> >>> The main form has multiple text boxes, combo boxes, lists...( a typical >>> data entry form). >>> >>> All the controls are bound to a dataview. >>> >>> I don't know how to select a particular record in a dataview. >>> >>> Because you cannot use find on a dataview unless the column in the >>> dataview is sorted. Which is not the case in mine. >>> >>> >>> "Bruce Wood" <brucew***@canada.com> wrote in message >>> news:1176055379.707713.3380@o5g2000hsb.googlegroups.com... >>>> On Apr 8, 9:49 am, "Hemang Shah" <hem***@hemang.net> wrote: >>>>> Thanks for the reply Alberto >>>>> >>>>> I got that far. Yours is a bit better than my idea, but what I did >>>>> is: >>>>> >>>>> On the main form, I created another dataview pointing to the same >>>>> table in >>>>> the same dataset and I was sending that to the child form. >>>>> >>>>> But the problem is, Now when a user clicks on an item in the child >>>>> form, the >>>>> main form doesn't point to that record (because the currencymanagers >>>>> are >>>>> different). >>>> >>>> First, a caveat: I've never used datagrids or currencymanagers. >>>> However, I have done the sort of thing you're trying to do in other >>>> situations. >>>> >>>> There are two possibilities (and you haven't really defined which one >>>> you're trying to achieve): 1) you want the main form to update as soon >>>> as the user clicks an item on the search form; 2) you want the main >>>> form to update as soon as the user clicks and item on the search form >>>> and dismisses it. >>>> >>>> In other words, is the search form running in parallel with the main >>>> form (searchForm.Show()) or is it a dialog (searchForm.ShowDialog())? >>>> >>>> In the first case, the solution is this: define an event on your >>>> search form: >>>> >>>> public event System.EventHandler UserSelectedItem; >>>> >>>> and a property: >>>> >>>> public XXX SelectedItem { get { ... } } >>>> >>>> Have your main form subscribe to the event. Whenever the event is >>>> raised, the main form will read the SelectedItem property, find the >>>> same item in its grid, and select it. >>>> >>>> On the other hand, if your search form is a dialog, you don't need the >>>> event, just the property. When the dialog returns, if the user clicked >>>> OK, the main form just reads the SelectedItem property and sets its >>>> current item accordingly. >>>> >>> >>> >> >> > >
Other interesting topics
Performance problems with OracleDataReader
Connection string / design question Increase Connection\ Command timeout globally Adding a non unique index to a datatable adding a column to a table Multiple relation in dataset. RichText in asp.net ADO.NET 2.0 - Binding a Second Form to the Same Data Source Yet another designer issue Dataadapter and where clause. |
|||||||||||||||||||||||