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

GridView ComboBox Column Issue

3 Answers 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt Greenwald
Top achievements
Rank 1
Matt Greenwald asked on 20 Jan 2010, 03:47 PM
Hello,
I am having a problem with a combo box column in my GridView using WPF. 
The gridview rows and combo box are bound to two separate collections, linked by a key of type integer.
When the gridview loads both the rows and combobox column are filled with the correct data, but when I try to update the value in the combobox (select a different value) it does not work. 
I can open the combobox list and see the different values available, but when I try to select a value in the combo box it reverts back to the original value.

My gridview is setup with the following xaml:
<telerik:RadGridView Name="rgvAppConfig" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollMode="RealTime" IsTabStop="False" 
                                             AutoGenerateColumns="False" ColumnsWidthMode="Auto" ItemsSource="{Binding}"                                                
                                            > 
                        <telerik:RadGridView.Columns> 
                                <telerik:GridViewDataColumn UniqueName="Id" IsVisible="False" /> 
                                <telerik:GridViewDataColumn UniqueName="MessageType" Header="Message Type"/> 
                                <telerik:GridViewDataColumn UniqueName="Description" Header="Description"/> 
                                <telerik:GridViewDataColumn UniqueName="SaveLocation" Header="Save Location"/> 
                                <telerik:GridViewDataColumn UniqueName="FieldDelimiter" Header="Field Delimiter"/> 
                                <telerik:GridViewDataColumn UniqueName="ComponentDelimiter" Header="Component Delimiter"/> 
                                <telerik:GridViewDataColumn UniqueName="SubComponentDelimiter" Header="SubComponent Delimiter"/> 
                            <telerik:GridViewComboBoxColumn UniqueName="ImageType" Header="Image Type" DisplayMemberPath="Name" DataMemberBinding="{Binding SaveImageType}" SelectedValueMemberPath="Id"  ItemsSource="{Binding}" /> 
                            <telerik:GridViewDataColumn UniqueName="Enabled" HeaderText="Enabled"/> 
                            </telerik:RadGridView.Columns> 
                        </telerik:RadGridView> 

</telerik:RadTabItem> 

Which is loaded with the following:
IList<Common.DAL.AppConfig> appConfig = 
                        (from x in Common.DAL.AppConfig.All() 
                         select x).ToList(); 
IList<Common.DAL.ComBinaryType> comBinaryType = 
                        (from x in Common.DAL.ComBinaryType.All() 
                         select x).ToList(); 
rgvAppConfig.Columns["ImageType"].DataContext = comBinaryType; 
rgvAppConfig.DataContext = appConfig; 

How can I resolve this so when a value it selected from the combo box it retains the value to was selected and updates the collection?

Thanks,
Matt

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Jan 2010, 09:05 AM
Hi Matt Greenwald,

Can you please paste me the implementation of the following classes :
1. Common.DAL.AppConfig
2. ComBinaryType

And I will try to resemble your scenario with a small sample project .

Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Matt Greenwald
Top achievements
Rank 1
answered on 25 Jan 2010, 03:28 PM
Hi Pavel,
Here are the classes you requested. I'm not sure if this will help you troubleshoot or not, but these classes were built using the subsonic v3 class generation tool.
public partial class AppConfig: IActiveRecord 
    { 
    
        #region Built-in testing 
        static TestRepository<AppConfig> _testRepo; 
         
 
         
        static void SetTestRepo(){ 
            _testRepo = _testRepo ?? new TestRepository<AppConfig>(new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB()); 
        } 
        public static void ResetTestRepo(){ 
            _testRepo = null
            SetTestRepo(); 
        } 
        public static void Setup(List<AppConfig> testlist){ 
            SetTestRepo(); 
            _testRepo._items = testlist; 
        } 
        public static void Setup(AppConfig item) { 
            SetTestRepo(); 
            _testRepo._items.Add(item); 
        } 
        public static void Setup(int testItems) { 
            SetTestRepo(); 
            for(int i=0;i<testItems;i++){ 
                AppConfig item=new AppConfig(); 
                _testRepo._items.Add(item); 
            } 
        } 
         
        public bool TestMode = false
        #endregion 
 
        IRepository<AppConfig> _repo; 
        ITable tbl; 
        bool _isNew; 
        public bool IsNew(){ 
            return _isNew; 
        } 
         
        public void SetIsLoaded(bool isLoaded){ 
            _isLoaded=isLoaded; 
            if(isLoaded) 
                OnLoaded(); 
        } 
         
        public void SetIsNew(bool isNew){ 
            _isNew=isNew; 
        } 
        bool _isLoaded; 
        public bool IsLoaded(){ 
            return _isLoaded; 
        } 
                 
        List<IColumn> _dirtyColumns; 
        public bool IsDirty(){ 
            return _dirtyColumns.Count>0; 
        } 
         
        public List<IColumn> GetDirtyColumns (){ 
            return _dirtyColumns; 
        } 
 
        CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB _db; 
        public AppConfig(string connectionString, string providerName) { 
 
            _db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(connectionString, providerName); 
            Init();             
         } 
        void Init(){ 
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase); 
            _dirtyColumns=new List<IColumn>(); 
            if(TestMode){ 
                AppConfig.SetTestRepo(); 
                _repo=_testRepo; 
            }else
                _repo = new SubSonicRepository<AppConfig>(_db); 
            } 
            tbl=_repo.GetTable(); 
            SetIsNew(true); 
            OnCreated();        
 
        } 
         
        public AppConfig(){ 
             _db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(); 
            Init();             
        } 
         
        
        partial void OnCreated(); 
             
        partial void OnLoaded(); 
         
        partial void OnSaved(); 
         
        partial void OnChanged(); 
         
        public IList<IColumn> Columns{ 
            get
                return tbl.Columns; 
            } 
        } 
 
        public AppConfig(Expression<Func<AppConfig, bool>> expression):this() { 
 
            SetIsLoaded(_repo.Load(this,expression)); 
        } 
         
        
         
        internal static IRepository<AppConfig> GetRepo(string connectionString, string providerName){ 
            CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB db; 
            if(String.IsNullOrEmpty(connectionString)){ 
                db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(); 
            }else
                db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(connectionString, providerName); 
            } 
            IRepository<AppConfig> _repo; 
             
            if(db.TestMode){ 
                AppConfig.SetTestRepo(); 
                _repo=_testRepo; 
            }else
                _repo = new SubSonicRepository<AppConfig>(db); 
            } 
            return _repo;         
        }        
         
        internal static IRepository<AppConfig> GetRepo(){ 
            CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB db; 
            db = new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(String.Format("Data Source={0}; Version=3", Path.Combine(Common.GetExecutingPath(Assembly.GetExecutingAssembly()), 
                                         "CardiacScienceMDI.sqlite")), "System.Data.SQLite"); 
            IRepository<AppConfig> _repo; 
             
            if(db.TestMode){ 
                AppConfig.SetTestRepo(); 
                _repo=_testRepo; 
            }else
                _repo = new SubSonicRepository<AppConfig>(db); 
            } 
            return _repo; 
        } 
         
        public static AppConfig SingleOrDefault(Expression<Func<AppConfig, bool>> expression) { 
 
            var repo = GetRepo(); 
            var results=repo.Find(expression); 
            AppConfig single=null
            if(results.Count() > 0){ 
                single=results.ToList()[0]; 
                single.OnLoaded(); 
                single.SetIsLoaded(true); 
                single.SetIsNew(false); 
            } 
 
            return single; 
        }       
         
        public static AppConfig SingleOrDefault(Expression<Func<AppConfig, bool>> expression,string connectionString, string providerName) { 
            var repo = GetRepo(connectionString,providerName); 
            var results=repo.Find(expression); 
            AppConfig single=null
            if(results.Count() > 0){ 
                single=results.ToList()[0]; 
            } 
 
            return single; 
 
 
        } 
         
         
        public static bool Exists(Expression<Func<AppConfig, bool>> expression,string connectionString, string providerName) { 
            
            return All(connectionString,providerName).Any(expression); 
        }         
        public static bool Exists(Expression<Func<AppConfig, bool>> expression) { 
            
            return All().Any(expression); 
        }         
 
        public static IList<AppConfig> Find(Expression<Func<AppConfig, bool>> expression) { 
             
            var repo = GetRepo(); 
            return repo.Find(expression).ToList(); 
        } 
         
        public static IList<AppConfig> Find(Expression<Func<AppConfig, bool>> expression,string connectionString, string providerName) { 
 
            var repo = GetRepo(connectionString,providerName); 
            return repo.Find(expression).ToList(); 
 
        } 
        public static IQueryable<AppConfig> All(string connectionString, string providerName) { 
            return GetRepo(connectionString,providerName).GetAll(); 
        } 
        public static IQueryable<AppConfig> All() { 
            return GetRepo().GetAll(); 
        } 
         
        public static PagedList<AppConfig> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) { 
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize); 
        } 
       
        public static PagedList<AppConfig> GetPaged(string sortBy, int pageIndex, int pageSize) { 
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize); 
        } 
 
        public static PagedList<AppConfig> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) { 
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize); 
             
        } 
 
 
        public static PagedList<AppConfig> GetPaged(int pageIndex, int pageSize) { 
            return GetRepo().GetPaged(pageIndex, pageSize); 
             
        } 
 
        public string KeyName() 
        { 
            return "Id"
        } 
 
        public object KeyValue() 
        { 
            return this.Id; 
        } 
         
        public void SetKeyValue(object value) { 
            if (value != null && value!=DBNull.Value) { 
                var settable = value.ChangeTypeTo<long>(); 
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null); 
            } 
        } 
         
        public override string ToString(){ 
            return this.MessageType.ToString(); 
        } 
 
        public override bool Equals(object obj){ 
            if(obj.GetType()==typeof(AppConfig)){ 
                AppConfig compare=(AppConfig)obj; 
                return compare.KeyValue()==this.KeyValue(); 
            }else
                return base.Equals(obj); 
            } 
        } 
 
        public string DescriptorValue() 
        { 
            return this.MessageType.ToString(); 
        } 
 
        public string DescriptorColumn() { 
            return "MessageType"
        } 
        public static string GetKeyColumn() 
        { 
            return "Id"
        }         
        public static string GetDescriptorColumn() 
        { 
            return "MessageType"
        } 
        
        #region ' Foreign Keys ' 
        #endregion 
         
 
        long _Id; 
        public long Id 
        { 
            get { return _Id; } 
            set 
            { 
                if(_Id!=value){ 
                    _Id=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Id"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _MessageType; 
        public string MessageType 
        { 
            get { return _MessageType; } 
            set 
            { 
                if(_MessageType!=value){ 
                    _MessageType=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="MessageType"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _Description; 
        public string Description 
        { 
            get { return _Description; } 
            set 
            { 
                if(_Description!=value){ 
                    _Description=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Description"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _SaveLocation; 
        public string SaveLocation 
        { 
            get { return _SaveLocation; } 
            set 
            { 
                if(_SaveLocation!=value){ 
                    _SaveLocation=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="SaveLocation"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _FieldDelimiter; 
        public string FieldDelimiter 
        { 
            get { return _FieldDelimiter; } 
            set 
            { 
                if(_FieldDelimiter!=value){ 
                    _FieldDelimiter=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="FieldDelimiter"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _ComponentDelimiter; 
        public string ComponentDelimiter 
        { 
            get { return _ComponentDelimiter; } 
            set 
            { 
                if(_ComponentDelimiter!=value){ 
                    _ComponentDelimiter=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="ComponentDelimiter"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _SubComponentDelimiter; 
        public string SubComponentDelimiter 
        { 
            get { return _SubComponentDelimiter; } 
            set 
            { 
                if(_SubComponentDelimiter!=value){ 
                    _SubComponentDelimiter=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="SubComponentDelimiter"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        long? _SaveImageType; 
        public long? SaveImageType 
        { 
            get { return _SaveImageType; } 
            set 
            { 
                if(_SaveImageType!=value){ 
                    _SaveImageType=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="SaveImageType"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        Boolean _Enabled; 
        public Boolean Enabled 
        { 
            get { return _Enabled; } 
            set 
            { 
                if(_Enabled!=value){ 
                    _Enabled=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Enabled"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
 
 
        public DbCommand GetUpdateCommand() { 
            if(TestMode) 
                return _db.DataProvider.CreateCommand(); 
            else 
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand(); 
             
        } 
        public DbCommand GetInsertCommand() { 
  
            if(TestMode) 
                return _db.DataProvider.CreateCommand(); 
            else 
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand(); 
        } 
         
        public DbCommand GetDeleteCommand() { 
            if(TestMode) 
                return _db.DataProvider.CreateCommand(); 
            else 
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand(); 
        } 
        
         
        public void Update(){ 
            Update(_db.DataProvider); 
        } 
         
        public void Update(IDataProvider provider){ 
         
             
            if(this._dirtyColumns.Count>0) 
                _repo.Update(this,provider); 
            OnSaved(); 
       } 
  
        public void Add(){ 
            Add(_db.DataProvider); 
        } 
         
         
        
        public void Add(IDataProvider provider){ 
 
             
            var key=KeyValue(); 
            if(key==null){ 
                var newKey=_repo.Add(this,provider); 
                this.SetKeyValue(newKey); 
            }else
                _repo.Add(this,provider); 
            } 
            SetIsNew(false); 
            OnSaved(); 
        } 
         
                 
         
        public void Save() { 
            Save(_db.DataProvider); 
        }       
        public void Save(IDataProvider provider) { 
             
            
            if (_isNew) { 
                Add(provider); 
                 
            } else { 
                Update(provider); 
            } 
             
        } 
 
         
 
        public void Delete(IDataProvider provider) { 
                    
                  
            _repo.Delete(KeyValue()); 
             
                    } 
 
 
        public void Delete() { 
            Delete(_db.DataProvider); 
        } 
 
 
        public static void Delete(Expression<Func<AppConfig, bool>> expression) { 
            var repo = GetRepo(); 
             
        
             
            repo.DeleteMany(expression); 
             
        } 
 
         
 
        public void Load(IDataReader rdr) { 
            Load(rdr, true); 
        } 
        public void Load(IDataReader rdr, bool closeReader) { 
            if (rdr.Read()) { 
 
                try { 
                    rdr.Load(this); 
                    SetIsNew(false); 
                    SetIsLoaded(true); 
                } catch { 
                    SetIsLoaded(false); 
                    throw
                } 
            }else
                SetIsLoaded(false); 
            } 
 
            if (closeReader) 
                rdr.Dispose(); 
        } 
         
 
    }  

public partial class ComBinaryType: IActiveRecord 
    { 
    
        #region Built-in testing 
        static TestRepository<ComBinaryType> _testRepo; 
         
 
         
        static void SetTestRepo(){ 
            _testRepo = _testRepo ?? new TestRepository<ComBinaryType>(new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB()); 
        } 
        public static void ResetTestRepo(){ 
            _testRepo = null
            SetTestRepo(); 
        } 
        public static void Setup(List<ComBinaryType> testlist){ 
            SetTestRepo(); 
            _testRepo._items = testlist; 
        } 
        public static void Setup(ComBinaryType item) { 
            SetTestRepo(); 
            _testRepo._items.Add(item); 
        } 
        public static void Setup(int testItems) { 
            SetTestRepo(); 
            for(int i=0;i<testItems;i++){ 
                ComBinaryType item=new ComBinaryType(); 
                _testRepo._items.Add(item); 
            } 
        } 
         
        public bool TestMode = false
        #endregion 
 
        IRepository<ComBinaryType> _repo; 
        ITable tbl; 
        bool _isNew; 
        public bool IsNew(){ 
            return _isNew; 
        } 
         
        public void SetIsLoaded(bool isLoaded){ 
            _isLoaded=isLoaded; 
            if(isLoaded) 
                OnLoaded(); 
        } 
         
        public void SetIsNew(bool isNew){ 
            _isNew=isNew; 
        } 
        bool _isLoaded; 
        public bool IsLoaded(){ 
            return _isLoaded; 
        } 
                 
        List<IColumn> _dirtyColumns; 
        public bool IsDirty(){ 
            return _dirtyColumns.Count>0; 
        } 
         
        public List<IColumn> GetDirtyColumns (){ 
            return _dirtyColumns; 
        } 
 
        CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB _db; 
        public ComBinaryType(string connectionString, string providerName) { 
 
            _db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(connectionString, providerName); 
            Init();             
         } 
        void Init(){ 
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase); 
            _dirtyColumns=new List<IColumn>(); 
            if(TestMode){ 
                ComBinaryType.SetTestRepo(); 
                _repo=_testRepo; 
            }else
                _repo = new SubSonicRepository<ComBinaryType>(_db); 
            } 
            tbl=_repo.GetTable(); 
            SetIsNew(true); 
            OnCreated();        
 
        } 
         
        public ComBinaryType(){ 
             _db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(); 
            Init();             
        } 
         
        
        partial void OnCreated(); 
             
        partial void OnLoaded(); 
         
        partial void OnSaved(); 
         
        partial void OnChanged(); 
         
        public IList<IColumn> Columns{ 
            get
                return tbl.Columns; 
            } 
        } 
 
        public ComBinaryType(Expression<Func<ComBinaryType, bool>> expression):this() { 
 
            SetIsLoaded(_repo.Load(this,expression)); 
        } 
         
        
         
        internal static IRepository<ComBinaryType> GetRepo(string connectionString, string providerName){ 
            CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB db; 
            if(String.IsNullOrEmpty(connectionString)){ 
                db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(); 
            }else
                db=new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(connectionString, providerName); 
            } 
            IRepository<ComBinaryType> _repo; 
             
            if(db.TestMode){ 
                ComBinaryType.SetTestRepo(); 
                _repo=_testRepo; 
            }else
                _repo = new SubSonicRepository<ComBinaryType>(db); 
            } 
            return _repo;         
        }        
         
        internal static IRepository<ComBinaryType> GetRepo(){ 
            CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB db; 
            db = new CardiacScience.MDI.Common.DAL.CardiacScienceMDIDB(String.Format("Data Source={0}; Version=3", Path.Combine(Common.GetExecutingPath(Assembly.GetExecutingAssembly()), 
                                         "CardiacScienceMDI.sqlite")), "System.Data.SQLite"); 
            IRepository<ComBinaryType> _repo; 
             
            if(db.TestMode){ 
                ComBinaryType.SetTestRepo(); 
                _repo=_testRepo; 
            }else
                _repo = new SubSonicRepository<ComBinaryType>(db); 
            } 
            return _repo; 
        } 
         
        public static ComBinaryType SingleOrDefault(Expression<Func<ComBinaryType, bool>> expression) { 
 
            var repo = GetRepo(); 
            var results=repo.Find(expression); 
            ComBinaryType single=null
            if(results.Count() > 0){ 
                single=results.ToList()[0]; 
                single.OnLoaded(); 
                single.SetIsLoaded(true); 
                single.SetIsNew(false); 
            } 
 
            return single; 
        }       
         
        public static ComBinaryType SingleOrDefault(Expression<Func<ComBinaryType, bool>> expression,string connectionString, string providerName) { 
            var repo = GetRepo(connectionString,providerName); 
            var results=repo.Find(expression); 
            ComBinaryType single=null
            if(results.Count() > 0){ 
                single=results.ToList()[0]; 
            } 
 
            return single; 
 
 
        } 
         
         
        public static bool Exists(Expression<Func<ComBinaryType, bool>> expression,string connectionString, string providerName) { 
            
            return All(connectionString,providerName).Any(expression); 
        }         
        public static bool Exists(Expression<Func<ComBinaryType, bool>> expression) { 
            
            return All().Any(expression); 
        }         
 
        public static IList<ComBinaryType> Find(Expression<Func<ComBinaryType, bool>> expression) { 
             
            var repo = GetRepo(); 
            return repo.Find(expression).ToList(); 
        } 
         
        public static IList<ComBinaryType> Find(Expression<Func<ComBinaryType, bool>> expression,string connectionString, string providerName) { 
 
            var repo = GetRepo(connectionString,providerName); 
            return repo.Find(expression).ToList(); 
 
        } 
        public static IQueryable<ComBinaryType> All(string connectionString, string providerName) { 
            return GetRepo(connectionString,providerName).GetAll(); 
        } 
        public static IQueryable<ComBinaryType> All() { 
            return GetRepo().GetAll(); 
        } 
         
        public static PagedList<ComBinaryType> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) { 
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize); 
        } 
       
        public static PagedList<ComBinaryType> GetPaged(string sortBy, int pageIndex, int pageSize) { 
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize); 
        } 
 
        public static PagedList<ComBinaryType> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) { 
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize); 
             
        } 
 
 
        public static PagedList<ComBinaryType> GetPaged(int pageIndex, int pageSize) { 
            return GetRepo().GetPaged(pageIndex, pageSize); 
             
        } 
 
        public string KeyName() 
        { 
            return "Id"
        } 
 
        public object KeyValue() 
        { 
            return this.Id; 
        } 
         
        public void SetKeyValue(object value) { 
            if (value != null && value!=DBNull.Value) { 
                var settable = value.ChangeTypeTo<long>(); 
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null); 
            } 
        } 
         
        public override string ToString(){ 
            return this.Name.ToString(); 
        } 
 
        public override bool Equals(object obj){ 
            if(obj.GetType()==typeof(ComBinaryType)){ 
                ComBinaryType compare=(ComBinaryType)obj; 
                return compare.KeyValue()==this.KeyValue(); 
            }else
                return base.Equals(obj); 
            } 
        } 
 
        public string DescriptorValue() 
        { 
            return this.Name.ToString(); 
        } 
 
        public string DescriptorColumn() { 
            return "Name"
        } 
        public static string GetKeyColumn() 
        { 
            return "Id"
        }         
        public static string GetDescriptorColumn() 
        { 
            return "Name"
        } 
        
        #region ' Foreign Keys ' 
        #endregion 
         
 
        long _Id; 
        public long Id 
        { 
            get { return _Id; } 
            set 
            { 
                if(_Id!=value){ 
                    _Id=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Id"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _Name; 
        public string Name 
        { 
            get { return _Name; } 
            set 
            { 
                if(_Name!=value){ 
                    _Name=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Name"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
        string _Description; 
        public string Description 
        { 
            get { return _Description; } 
            set 
            { 
                if(_Description!=value){ 
                    _Description=value; 
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Description"); 
                    if(col!=null){ 
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){ 
                            _dirtyColumns.Add(col); 
                        } 
                    } 
                    OnChanged(); 
                } 
            } 
        } 
 
 
 
        public DbCommand GetUpdateCommand() { 
            if(TestMode) 
                return _db.DataProvider.CreateCommand(); 
            else 
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand(); 
             
        } 
        public DbCommand GetInsertCommand() { 
  
            if(TestMode) 
                return _db.DataProvider.CreateCommand(); 
            else 
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand(); 
        } 
         
        public DbCommand GetDeleteCommand() { 
            if(TestMode) 
                return _db.DataProvider.CreateCommand(); 
            else 
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand(); 
        } 
        
         
        public void Update(){ 
            Update(_db.DataProvider); 
        } 
         
        public void Update(IDataProvider provider){ 
         
             
            if(this._dirtyColumns.Count>0) 
                _repo.Update(this,provider); 
            OnSaved(); 
       } 
  
        public void Add(){ 
            Add(_db.DataProvider); 
        } 
         
         
        
        public void Add(IDataProvider provider){ 
 
             
            var key=KeyValue(); 
            if(key==null){ 
                var newKey=_repo.Add(this,provider); 
                this.SetKeyValue(newKey); 
            }else
                _repo.Add(this,provider); 
            } 
            SetIsNew(false); 
            OnSaved(); 
        } 
         
                 
         
        public void Save() { 
            Save(_db.DataProvider); 
        }       
        public void Save(IDataProvider provider) { 
             
            
            if (_isNew) { 
                Add(provider); 
                 
            } else { 
                Update(provider); 
            } 
             
        } 
 
         
 
        public void Delete(IDataProvider provider) { 
                    
                  
            _repo.Delete(KeyValue()); 
             
                    } 
 
 
        public void Delete() { 
            Delete(_db.DataProvider); 
        } 
 
 
        public static void Delete(Expression<Func<ComBinaryType, bool>> expression) { 
            var repo = GetRepo(); 
             
        
             
            repo.DeleteMany(expression); 
             
        } 
 
         
 
        public void Load(IDataReader rdr) { 
            Load(rdr, true); 
        } 
        public void Load(IDataReader rdr, bool closeReader) { 
            if (rdr.Read()) { 
 
                try { 
                    rdr.Load(this); 
                    SetIsNew(false); 
                    SetIsLoaded(true); 
                } catch { 
                    SetIsLoaded(false); 
                    throw
                } 
            }else
                SetIsLoaded(false); 
            } 
 
            if (closeReader) 
                rdr.Dispose(); 
        } 
         
 
    }  

Thanks,
Matt
0
Pavel Pavlov
Telerik team
answered on 29 Jan 2010, 10:51 AM
Hello Matt ,
Please excuse me for the delay . I was trying to reproduce the problem  but with no success so far.
I am attaching a small test project . It contains your xaml and trimmed data classes ( with only the relevaant properties ) . If you manage to reproduce the problem by modifying it it - please let me know .. otherwise I thing the problem might be in the data layer   rather than in RadGridView.

Sincerely yours,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Matt Greenwald
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Matt Greenwald
Top achievements
Rank 1
Share this question
or