Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Current view of DataGridView as DataView
 

Current view of DataGridView as DataView

Apologies if the title of this question is a little confusing. I have a method that accepts a DataView object and a file name/open stream and dumps the contents of the DataView to the file/stream. I want to pass the current view of a DataGridView control to the method preserving the layout and filtering but I don't know how to do this. I can pass in the underlying DataSource but that will include hidden columns and will lose the filters.

Is there a way to create a DataView from what is displayed in the grid or will I have to iterate through the grid building a new DataView object?

Regards,

Neil.
The Original Mr B  Thursday, September 03, 2009 11:08 AM
Hi The Original Mr B,

Based on my understanding, you want to persist the information of the DataGridView as DataView. As far as I know, there is no such way, but we can use other methods to save and fetch the information of the DataGridView, such as save the information as a xml document or a text. For eample, if you want to persist the information of the DataGridView to a xml, the file/stream can be like this:
<?xml version="1.0" encoding="utf-8" ?>
<DataGridView name="dgv">
  <columns>
    <column name="col1" filter="col1>1" visible="true"></column>
    <column name="col2" filter="col2='good'" visible="true"></column>
    <column name="col3" filter="" visible="false"></column>
  </columns>
  <data>
    <!--persist data here-->
  </data>
</DataGridView>
Let me know if this helps or not.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 6:24 AM

Hi,

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 11, 2009 2:05 AM

You can use google to search for other answers

Custom Search

More Threads

• Host Controls in Windows Forms DataGridView Cells
• How to have transaction control on two adapters?
• Is it possible to disable soft wrapping in DataGridView, but still wrap text?
• Newbie problem: updating data in Win Forms using a BindingSource
• Obscure bug in DataGrid + DataTable - Need confirmation
• DataGridView RightToLeft Property doesnt work?
• Issues exposing a DataGridView control in a User Control
• datagridview bit column - display something other than True/False?
• BLOB or link to file ????
• DataSet, Xml code and Images!