This is a migrated thread and some comments may be shown as answers.

GridView Combobox

1 Answer 109 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
OverCoded asked on 28 Jul 2010, 03:14 PM
I have a RadGrid that is being used to display settings for a user control. One of the settings is a font listing for each label on the control. I need this column to be a combobox-column. The problem I am having is that when I use the recommended approach to populating the data for this column I get a choice of only those fonts that have be set and listed in the database. What I need is a combobox in the datagrid with a listing of the system fonts as the ItemSource and the DisplayMemberPath, and SelectedValueMemberPath pointing to the data source. However, this does not seems to work. I think that the only way to do this is to provide some sort of datatable with a column having the same name as the targeted "Font Column" in the data source. Any ideas?

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 28 Jul 2010, 07:19 PM

Okay, never mind. after a day and a half I figured it out. I created a dataset class to hold the font listing. It has a single column with the same name as the one in the database. In may case it is called "FONT_NAMES." When I populated the data table I padded the font name with the number of characters allowed in the database to force a match with listing in the database. see below:
*Note this is in a WPF App*

private FontListDataTable sysFonts; //Global variable custom dataTable class.
sysFonts = new FontListDataTable(); //Itialized in the constructor.
//(2)Poplate the combobox
    ((GridViewComboBoxColumn)radgrid.Columns["fontColumn"]).ItemsSource = FontList();((GridViewComboBoxColumn)radgrid.Columns["fontColumn"]).DisplayMemberPath = "FONT_NAME"
((GridViewComboBoxColumn)radgrid.Columns["fontColumn"]).SelectedValueMemberPath = "FONT_NAME"
// (3)Poplate the Datatable with font names from the system
private IEnumerable<DataRow> FontList() 
            foreach (FontFamily font in Fonts.SystemFontFamilies) 
            return sysFonts.AsEnumerable(); 
// The Custom datatable Class
class FontListDataTable : DataTable 
        private global::System.Data.DataColumn columnFONT_NAME; 
        public FontListDataTable() 
        public global::System.Data.DataColumn FONT_NAMEColumn 
                return this.columnFONT_NAME; 
        public FontNameRow AddFontNameRow(string FONT_NAME) 
            FontNameRow rowFontListDataTableRow = ((FontNameRow)(this.NewRow())); 
            object[] columnValuesArray = new object[]{ 
            rowFontListDataTableRow.ItemArray = columnValuesArray; 
            return rowFontListDataTableRow; 
        internal void InitVars() 
            this.columnFONT_NAME = base.Columns["FONT_NAME"]; 
        private void InitClass() 
            this.columnFONT_NAME = new global::System.Data.DataColumn("FONT_NAME", typeof(string), null, global::System.Data.MappingType.Element); 
        protected override DataTable CreateInstance() 
            return new FontListDataTable(); 
        public FontNameRow NewFontNameRow() 
            return ((FontNameRow)(this.NewRow())); 
        protected override global::System.Data.DataRow NewRowFromBuilder(global::System.Data.DataRowBuilder builder) 
            return new FontNameRow(builder); 
        protected override global::System.Type GetRowType() 
            return typeof(FontNameRow); 
        /// <summary> 
        ///Represents strongly named DataRow class. 
        public partial class FontNameRow : global::System.Data.DataRow 
            private FontListDataTable tableFontList; 
            internal FontNameRow(global::System.Data.DataRowBuilder rb) : 
                this.tableFontList = ((FontListDataTable)(this.Table)); 
            public string FONT_NAME 
                    return ((string)(this[this.tableFontList.FONT_NAMEColumn])); 
                    this[this.tableFontList.FONT_NAMEColumn] = value; 
Asked by
Top achievements
Rank 2
Answers by
Top achievements
Rank 2
Share this question