Print Page | Close Window

Bind to existing grid column?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=551
Printed Date: 19-Sep-2025 at 2:27am


Topic: Bind to existing grid column?
Posted By: Matthew
Subject: Bind to existing grid column?
Date Posted: 15-Nov-2007 at 4:47pm
I have a Winforms DataGridView on a form to which I have added a few columns.  These columns inherit from DataGridViewTextBoxColumn.  Is there a way to have the Devforce grid binding manager use the existing columns instead of creating its own new columns?

I assumed that was why I would pass in the "typeof(TypeOfGridColumnHere)" when adding a descriptor, but in the end a standard winform textboxcolumn is added.

Thank you,
Matthew



Replies:
Posted By: jasonk
Date Posted: 19-Nov-2007 at 9:32am

You should be able to programmatically bind an existing column that has the same binding property path.  See below sample.

private void AddColumn(string pPropertyPath, string text) {

      ViewDescriptor vd = new ViewDescriptor(typeof(Customer), pPropertyPath);

      DataGridViewBindingDescriptor dgvbd = dataGridViewBindingManager1.Descriptors.Add(vd);

      dgvbd.Column.HeaderText = text;

    }

However, if the column is not bound or it is bound to a different property path, the “dataGridViewBindingManager1.Descriptors.Add” call will add a new column instead.

If there is another column that is also bound to the same property path and it has a valid ViewDescriptor, DF will also add a new column and ViewDescriptor.

 

Jason




Print Page | Close Window