Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Databinding DataGridView.Columns to edit at runtime
 

Databinding DataGridView.Columns to edit at runtime

I'm creating an application where I would like the user to be able to change the columns of a DataGridView at runtime. 

So far, I've been able to bind the columns to a listbox, in order to list and select the columns individually.  However, I can't seem to choose what is displayed in my list box.

I have the following code:
listBoxDataColumns.DataSource = dataGridViewData.Columns;
listBoxDataColumns.DisplayMember = "Name";
My listbox then displays something like:
DataGridViewTextBoxColumn {Name=ID, Index=0 }
DataGridViewTextBoxColumn {Name=Value, Index=1 }
and so on...

How would I display only the Name portion of the column in this list?

Is there an easier way to allow the user to change the columns at runtime?  I'm primarily interested in allowing them to add/delete columns, and rename the columns.

Thanks!

Gabe

Gabe Covert  Wednesday, October 07, 2009 7:02 PM

listBoxDataColumns.DisplayMember = "HeaderText";

is this what you are looking for.

  • Marked As Answer byGabe Covert Wednesday, October 07, 2009 7:34 PM
  •  
Tamer Oz  Wednesday, October 07, 2009 7:31 PM

listBoxDataColumns.DisplayMember = "HeaderText";

is this what you are looking for.

  • Marked As Answer byGabe Covert Wednesday, October 07, 2009 7:34 PM
  •  
Tamer Oz  Wednesday, October 07, 2009 7:31 PM

listBoxDataColumns.DisplayMember = "HeaderText" ;

is this what you are looking for.

That's it exactly!

Thanks!

Gabe
Gabe Covert  Wednesday, October 07, 2009 7:35 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridViewComboBoxCell Value is not Valid
• Dynamic Database Connection
• Scenario for Dynamic Data Population for Grid View!
• Is ListBox the only control in Forms to allow multiple selections?
• VS 2005 - Easiest way to get two related tables in one datagridview?
• Directory Polling with Windows Service
• DataGridView and new rows
• InvalidOperationException with DataGridView bound to object data source
• DataGridView Update Problem with BL Layer
• DataGridView 2.0