storing a DataGridView in a Setting

  • Thread starter Thread starter michael sorens
  • Start date Start date
M

michael sorens

Is it possible to store an unbound DataGridView component into a setting?
I naively tried defining a Setting that is a DataGridView called DGV, then
simply assigning it:
Properties.Settings.Default.DGV = myDataGridView;
After I closed the program, the user.config file shows an empty value, so
apparently that is not the way to do it.
 
michael said:
Is it possible to store an unbound DataGridView component into a
setting? I naively tried defining a Setting that is a DataGridView
called DGV, then simply assigning it:
Properties.Settings.Default.DGV = myDataGridView;
After I closed the program, the user.config file shows an empty value,
so apparently that is not the way to do it.
I never found a way to do it -- tried dozens of methods. I finally gave up and just bound the DataGridView to a DataSource and serialized the underlying DataSet.
 
Hi,

I don't think you can store the DataGridView into a setting, because the
DataGridView itself doesn't contain any data. The data is stored in the
underlying DataSource. So, it will be better to store the datasource
instead. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin said:
I don't think you can store the DataGridView into a setting, because the
DataGridView itself doesn't contain any data. The data is stored in the
underlying DataSource. So, it will be better to store the datasource
instead. HTH.

So, what's the datasource of an unbound DataGridView? Specifically, I had a DataGridView displaying the files selected from an OpenFileDialog. Those file names were used by other methods just fine, but there appeared to be no way to serialize those names.
 
Actually, Ken, you can't store a DataGridView in the Settings file because
it isn't Serializable.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
Hi Ken,

This depends on how you display data on the DataGridView. Could you show us
some of your code that put data on the datagridView?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin said:
Hi Ken,

This depends on how you display data on the DataGridView. Could you show us
some of your code that put data on the datagridView?

Unfortunately, I no longer can show how I was populating the unbound DataGridView--now that I'm using a bound DataGridView, the current code shows how I'm populating it's underlying dataset and I don't have samples of the previous code.
 
So how do I connect the DataGridView to a DataSource after I have filled
the DataGridView?
 
michael said:
So how do I connect the DataGridView to a DataSource after I have filled
the DataGridView?

I did all the work in the VS2005 IDE: I created a dataset from an XSD file (using XSD.exe), added it to the project and after compiling added it as a DataSource in VS2005. The appropriate BindingSource was automagically added and I simply dragged the DataGridView from the DataSource Explorer onto my form. After that, I wrote my code to populate the DataSet, not the DataGridView.
 
Hi,

Actually, you're not filling the DataGridView itself. You're filling the
DataSource. After you have filled it, just use DataGridView.DataSource =
dataset; to bind it. (Assume the data source is a dataset.)

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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

Back
Top