dead cycling in CreateCellElement

7 posts, 0 answers
  1. xiaofeng
    xiaofeng avatar
    60 posts
    Member since:
    Jun 2008

    Posted 24 Oct 2009 Link to this post

    I define a ImageColumn.It inherits from a GridViewDataColumn.My version is Q3.
    The data source of the grid is only one row.But when I scroll the horizonal scroll bar,the grid and the projects will crash.I set a break point in CreateCellElement.It seems like this method is always executing.I seems like a dead cycling.I do not what happening.Can you
    analyse  the reason for me?Thank you very much.
     public class UserImage 
       { 
          public byte[] ImageStream; 
          public string ImageUrl { getset; } 
          public string ImageName { getset; } 
       } 
       public class ImageColumn : GridViewDataColumn 
       { 
     
          private string _DispalyMemberPath = string.Empty; 
          public string DispalyMemberPath  
          { 
             get 
             { 
                return _DispalyMemberPath; 
             } 
             set 
             {  
                _DispalyMemberPath = value; 
             }  
          } 
     
          private string GetUrl(object dataItem) 
          { 
             PropertyInfo CurProp = dataItem.GetType().GetProperty(_DispalyMemberPath); 
             UserImage img = CurProp.GetValue(dataItem, nullas UserImage; 
             if (img == null
             { 
                return string.Empty; 
             } 
             if (img.ImageUrl == null
             { 
                return string.Empty; 
             } 
             else 
             { 
                return img.ImageUrl; 
             } 
     
          } 
     
          private byte[] GetImageStream(object dataItem) 
          { 
             PropertyInfo CurProp = dataItem.GetType().GetProperty(_DispalyMemberPath); 
             UserImage img = CurProp.GetValue(dataItem, nullas UserImage; 
             if (img == null
             { 
                return new byte[0]; 
             } 
             if (img.ImageStream == null
             { 
                return new byte[0]; 
             } 
             else 
             { 
                return img.ImageStream; 
             } 
     
          } 
     
          private string GetImageName(object dataItem) 
          { 
             PropertyInfo CurProp = dataItem.GetType().GetProperty(_DispalyMemberPath); 
             UserImage img = CurProp.GetValue(dataItem, nullas UserImage; 
             if (img == null
             { 
                return string.Empty; 
             } 
             if (img.ImageName == null
             { 
                return string.Empty; 
             } 
             else 
             { 
                return img.ImageName; 
             } 
     
          } 
          public Stream BytesToStream(byte[] bytes) 
          { 
             Stream stream = new MemoryStream(bytes); 
             return stream; 
          } 
          public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) 
          { 
             StackPanel panel = new StackPanel(); 
     
             var cellImage = new Image(); 
             BitmapImage img = new BitmapImage(); 
             string imageUri = GetUrl(dataItem); 
             byte[] imageStream = GetImageStream(dataItem); 
             if (imageUri != string.Empty) 
             { 
                img.UriSource = new Uri(imageUri, UriKind.RelativeOrAbsolute); 
             } 
             else if (imageStream.Length > 0) 
             { 
                img.SetSource(BytesToStream(imageStream)); 
             } 
     
             cellImage.Source = img; 
             panel.Children.Add(cellImage); 
     
             var imageName = GetImageName(dataItem); 
             if (imageName != string.Empty) 
             { 
                TextBlock txt = new TextBlock(); 
                txt.Text = imageName; 
                panel.Children.Add(txt); 
             } 
             return panel; 
          } 
       } 

  2. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 24 Oct 2009 Link to this post

    if your point is to create a column that holds an image in the radgridview, instead of creating a custom gridviewdatacolumn, can't you just use a gridviewimagecolumn and us the celltemplate to customize your display ?
  3. DevCraft banner
  4. xiaofeng
    xiaofeng avatar
    60 posts
    Member since:
    Jun 2008

    Posted 24 Oct 2009 Link to this post

    Does your grid have gridviewimagecolumn ?You gave the solution about custom gridviewdatacolumn when we use Q2.
  5. Missing user
    Missing user avatar

    Posted 25 Oct 2009 Link to this post

    Hello xiaofeng,

    Yes , we have introduced a new column type called GridViewImageColumn with our second beta.It will allow you to easily add dynamic image columns.  You can check our online demo out:
    http://demos.telerik.com/silverlight/beta/#GridView/ColumnTypes
    Also our next Q3 official release is just around the corner - it is scheduled for the beggining of November.

    Best wishes,

    Anastasia
    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.
  6. Simon yang
    Simon yang avatar
    15 posts
    Member since:
    Sep 2009

    Posted 25 Oct 2009 Link to this post

    xaml: 
    <telerikGridView:RadGridView x:Name="grdLoanHistory" TabIndex="15" Margin="0,0,0,2" Grid.Row="4" Grid.Column="1"
                     
    Grid.ColumnSpan="7"  
                      IsFilteringAllowed="False" CanUserResizeColumns="True"  
                      IsReadOnly="True" AutoGenerateColumns="False"  
                      ShowGroupPanel="False"   CanUserFreezeColumns="False" MultipleSelect="False"  
                      DataLoadMode="Synchronous" ItemsSource="{Binding LoanHistoryList}" ScrollMode="RealTime" 
                      SelectedItem="{Binding SelectedLoanHistory, Mode=TwoWay}" FontSize="10" ><!--Height="236"--> 
    </telerikGridView:RadGridView> 
    C#: 
    private void InitialGrid() 
          { 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(64023), "Title", "t02Titles", 140d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(52523), "CallNo", "NormalizedCallNo", 120d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(52507), "Author", "Author", 100d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(65409), "CopyBarcode", "CopyBarcode", 120d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(65439), "PatronName", "PatronName", 130d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(600027), "CheckoutDate", "dCheckoutDate", 130d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(2215053), "CheckinDate", "dCheckinDate", 130d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(52525), "DueDate", "dDueDate", 130d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(52540), "dPrice", "dPrice", 70d, "{0:c}")); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(56303), "CheckoutLibraryID", "CheckoutLibraryID", 130d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(56305), "CopyLibraryID", "CopyLibraryID", 120d)); 
             this.grdLoanHistory.Columns.Add(CreateColumn(Global.GetCaption(65415), "CheckoutNotes", "CheckoutNotes", 180d)); 
          } 
          private GridViewDataColumn CreateColumn(string headerText, string dataPath, string sortstring, double width) 
          { 
             GridViewDataColumn columnOrderEmployeeFirstName = new GridViewDataColumn(); 
             //columnOrderEmployeeFirstName.DataType = columnType
             columnOrderEmployeeFirstName.Header = headerText
             columnOrderEmployeeFirstName.DataMemberBinding = new Binding(dataPath); 
             columnOrderEmployeeFirstName.Width = new GridViewLength(width); 
             columnOrderEmployeeFirstName.SortMemberPath = sortstring
             return columnOrderEmployeeFirstName; 
          } 
          private GridViewDataColumn CreateColumn(string headerText, string dataPath, string sortstring, double width, string format) 
          { 
             GridViewDataColumn columnOrderEmployeeFirstName = new GridViewDataColumn(); 
             //columnOrderEmployeeFirstName.DataType = columnType
             columnOrderEmployeeFirstName.Header = headerText
             columnOrderEmployeeFirstName.DataMemberBinding = new Binding(dataPath); 
             columnOrderEmployeeFirstName.Width = new GridViewLength(width); 
             columnOrderEmployeeFirstName.DataFormatString = format
             columnOrderEmployeeFirstName.SortMemberPath = sortstring
             return columnOrderEmployeeFirstName; 
          } 
    I scroll the horizonal scroll bar,the grid crash too.Now my version is Beta2_2009_3_1023.Anyone give me an  answer?Thanks!
  7. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 28 Oct 2009 Link to this post

    Hi Simon yang,

    We are unable to reproduce this issue.
    Could you send us sample project demonstrating it so that we can investigate it further?

    All the best,
    Hristo
    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.
  8. xiaofeng
    xiaofeng avatar
    60 posts
    Member since:
    Jun 2008

    Posted 02 Nov 2009 Link to this post

    Hi!If I use the gridviewimagecolumn .How can I create a celltemplate in c#?Thank you!
Back to Top
DevCraft banner