DataGridView question...

  • Thread starter supersonicsilence
  • Start date
S

supersonicsilence

Hi all, I am having a bit of an issue with DataGridView in c#.

I am binding the datagridview to a data table. The data table has 5
columns (a,b,c,d,e). In the designer for the DataGridView, I create
three columns ... one for a, one for b, and one for c. I set the c
column visible to false.

When I run the program, which does not immediately populate the
DataGridView, only columns a and b show up. But when I click the
button that causes the DataGridView to populate, suddenly all 5
columns are there?

All I do in the code is something like this:

DataTable dt = <some code to populate the data table>
myDataGridView.DataSource = dt;

Why are the extra columns showing up, and how can I prevent them from
showing up?

Also, maybe a better question is this - I need columns c, d and e
because they contain data I need once the user selects an item from
the data grid view. Is there an easy way to store these in separate
data store and not even include these columns in the DataTable I pass
to the data grid view, but with which I can still easily map the
user's selected rows to correlate it with the column c, d and e data?
 
A

Amien Crombie

Hi all, I am having a bit of an issue with DataGridView in c#.

I am binding the datagridview to a data table. The data table has 5
columns (a,b,c,d,e). In the designer for the DataGridView, I create
three columns ... one for a, one for b, and one for c. I set the c
column visible to false.

When I run the program, which does not immediately populate the
DataGridView, only columns a and b show up. But when I click the
button that causes the DataGridView to populate, suddenly all 5
columns are there?

All I do in the code is something like this:

DataTable dt = <some code to populate the data table>
myDataGridView.DataSource = dt;

Why are the extra columns showing up, and how can I prevent them from
showing up?

Also, maybe a better question is this - I need columns c, d and e
because they contain data I need once the user selects an item from
the data grid view. Is there an easy way to store these in separate
data store and not even include these columns in the DataTable I pass
to the data grid view, but with which I can still easily map the
user's selected rows to correlate it with the column c, d and e data?

Hi

Looks like you design 3 columns in designer and then creates them in
code as well.
Either create columns in designer or in code.

Bye
 

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