Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView: changing DataMember displays no data, though the data is 'there'
 

DataGridView: changing DataMember displays no data, though the data is 'there'

Overview

I am using Windows.Forms.

I have a typed dataset with three tables (defined in a dll) I want to display in the DataGridView. I can see the data in the tables using the debugger, but I cannot change the view from one table to another - actually, I think the data might change, but the columns do not display properly.

Detail

I have aBindingSource defined usingthe dataset as the DataSource.

I have a BindingNavigator defined on the BindingSource. (That appears to work properly. I.E. when I change the data member the number of records changes to the number of records in the table.)

And I have the DataGridView using the BindingSource as the DataSource.

If I select a table as the DataMember in the IDE, I can display that table properly. However, when I change the DataMember in code, the column headers do not change. N.B. Two of the tables have a common field name. If I use one of these tables as the DataMember and change to the other, only the common field has data.

If I do not specify a table name in the IDE and try to set it in code, i.e. dgv.DataMember = "tableName"; *no* columns are displayed.

I have great confidence that I'm just not setting some attribute in the dgv, but the closest thing I've seen applies to the Web control, not the Forms control.

ramsey  Tuesday, October 09, 2007 2:47 PM

Ok. I R A idjit.

The magic parameter seems to be DataGridView.AutoGenerateColumns. This is what I found that referenced Web development.

N.B. It does not show up via intelesense or in the properties for the control, but, once you code it, hover help shows correct help.

HOWEVER, the default is *supposed to be* true. I couldn't get the columns to regenerate until I added dgv.AutoGenerateColumns = true; to my code. The debugger reported that the value was set to false before I set it.

So, I guess, why is this not documented appropriately? Or please direct me to where it *is* documented.

ramsey  Tuesday, October 09, 2007 6:28 PM

Ok. I R A idjit.

The magic parameter seems to be DataGridView.AutoGenerateColumns. This is what I found that referenced Web development.

N.B. It does not show up via intelesense or in the properties for the control, but, once you code it, hover help shows correct help.

HOWEVER, the default is *supposed to be* true. I couldn't get the columns to regenerate until I added dgv.AutoGenerateColumns = true; to my code. The debugger reported that the value was set to false before I set it.

So, I guess, why is this not documented appropriately? Or please direct me to where it *is* documented.

ramsey  Tuesday, October 09, 2007 6:28 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridViewComboBoxColumn drop down not displaying when DataPropertyName assigned
• BindingSource BindingComplete Event
• DataGridView add row side by side
• Display stored procedure with dynamic columns in datagridview
• My data is not being saved to my database!
• column caption
• Customized Datagrid
• DataGridView - How is mouseDown implemented?
• Get distinct Rows in DataTable?
• Typed DataSet