How to bind ComboBox's ItemSource to DataGrid's headers?


hi all.

i have a datagrid whose itemsource bound observablecollection, filled a wcf service.

its columns autogenerated.

 

how can set combobox's itemssource datagrid's headers?

 

ultimately i'm using  combobox to provide search criteria when searching the datagrid -

so users select a column in combobox, enter keyword search for in textbox.

how this:

void datagrid1_layoutupdated(object sender, eventargs e)  {      list<string> columnheaders = new list<string>();      (int j = 0; j < this.datagrid1.columns.count; j++)      {      columnheaders.add(          datagrid1.columns[j].header.tostring());      }      this.columnheaders.itemssource = columnheaders;  }

note: j used indexer no other reason than, on site, using creates idea emote when accessing headers yell

basically, on event datagrid updated, create new list (or declare observablecollection in class , use that) , interate across list of columns in dataset, adding column.header value list. (i'm assuming columns contain strings). if use class-level observablecollection, ensure clear list, or add logic check duplicate header names, prevent these getting combobox. there might linq statement makes tidier...

i tried , works fine. don't know of "tidier" way of doing this, because datagrid object doesnt store collection of column headers; stores collection of columns, each of has header :p

hth...



Silverlight  >  Silverlight Controls and Silverlight Toolkit



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607