How to manage a datagrid with 2 dataview as possible datasource?

G

Guest

Hi, I'm using vs2005, .net 2 for windows applciation. I have a form with 1
datagrids whose datasource comes from 2 dataview that are based on 2 dataset
datatables(depends on the stat of the application then one of the dataview
will be selected as datasource for the grid). Both dataview have only 2
columns but one of the columns name is different. Depending on the state of
the application, I would need to change the datasource to be attached to the
datagrid. This is where the problem occurs. The grid has a column created
in the designer that is looking for certain column name in the other dataview
as a datasource. Do I remove and save the column in the grid, add the new
columns name column and reverse it when the application changes? Or, would
it be better if I just create and layer another gird and hide one of the grid
according to the application state? Which would be a better performance
solution? I expect the grid to contain the most is a couple of thousands of
rows.
 
M

MasterGaurav \(www.edujini-labs.com\)

columns but one of the columns name is different. Depending on the state
of
the application, I would need to change the datasource to be attached to
the
datagrid. This is where the problem occurs. The grid has a column
created

Keep the data-views in Session, if they're user dependent.
Or else, keep them in Cache. Pick the one needed.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
M

MasterGaurav \(www.edujini-labs.com\)

columns but one of the columns name is different. Depending on the state
of
the application, I would need to change the datasource to be attached to
the
datagrid. This is where the problem occurs. The grid has a column
created

Keep both of them in memory.
When needed, use DataGrid.SetDataBinding(<data-view>, "") to switch from one
view to another.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
G

Guest

Ignore which posting? You think it's better if I don't create an additional
grid to hold the 2nd dataview? I tried switching by setting datasource but
the grid complaint about not able to find the column from the other dataview.
How shoud I address this?
 
M

MasterGaurav \(www.edujini-labs.com\)

Ignore which posting? You think it's better if I don't create an
additional

Ignore the one using "Session/Cache" :)
grid to hold the 2nd dataview? I tried switching by setting datasource
but
the grid complaint about not able to find the column from the other
dataview.
How shoud I address this?

How are you setting the data source?
You should use the method SetDataBinding in .Net 2.0


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
G

Guest

I'm using datagridview and there is no SetDatabinding available. I can
either set datasource or set databinding. Thanks.
 
M

MasterGaurav \(www.edujini-labs.com\)

I'm using datagridview and there is no SetDatabinding available. I can
either set datasource or set databinding. Thanks.

Ah! Your earlier posting(s) and even the subject reads "DataGrid". Fix that
:)

There are two things while setting the DataSource.

1. As soon as the DataSource is set, OnDataSourceChanged method is called
which, apart from other things, refreshes the grid and raises the
DataSourceChanged event
2. If the DataSource instance set is same as the previously set instance,
irrespective of whether the content in the source has changed or not, the
refresh will not happen. If saves precious time and CPU-cycles.

To get across the problem arising out of second scenario, first set the
value of DataSource to null and then to the same input once again.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 

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