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

GridView Combobox

1 Answer 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
OverCoded
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
0
OverCoded
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*

//(1)
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) 
            
                sysFonts.AddFontNameRow(font.ToString().PadRight(18)); 
            }             
            return sysFonts.AsEnumerable(); 
        
// The Custom datatable Class
class FontListDataTable : DataTable 
    
    
        private global::System.Data.DataColumn columnFONT_NAME; 
    
        public FontListDataTable() 
        
            this.InitVars(); 
            this.InitClass(); 
        
    
        public global::System.Data.DataColumn FONT_NAMEColumn 
        
            get
            
                return this.columnFONT_NAME; 
            
        
    
        public FontNameRow AddFontNameRow(string FONT_NAME) 
        
            FontNameRow rowFontListDataTableRow = ((FontNameRow)(this.NewRow())); 
            object[] columnValuesArray = new object[]{ 
                FONT_NAME 
            }; 
            rowFontListDataTableRow.ItemArray = columnValuesArray; 
            this.Rows.Add(rowFontListDataTableRow); 
            return rowFontListDataTableRow; 
        
    
        internal void InitVars() 
        
            //**!THIS COLUMN MUST MATCH THE DATABASE COLUMN!!
            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); 
            base.Columns.Add(this.columnFONT_NAME); 
        
    
        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. 
        ///</summary> 
        public partial class FontNameRow : global::System.Data.DataRow 
        
            private FontListDataTable tableFontList; 
    
            internal FontNameRow(global::System.Data.DataRowBuilder rb) : 
                base(rb) 
            
                this.tableFontList = ((FontListDataTable)(this.Table)); 
            
    
            public string FONT_NAME 
            
                get
                
                    return ((string)(this[this.tableFontList.FONT_NAMEColumn])); 
                
                set
                
                    this[this.tableFontList.FONT_NAMEColumn] = value; 
                
            
         
    }
Tags
GridView
Asked by
OverCoded
Top achievements
Rank 2
Answers by
OverCoded
Top achievements
Rank 2
Share this question
or