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

dead cycling in CreateCellElement

6 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
xiaofeng
Top achievements
Rank 1
xiaofeng asked on 24 Oct 2009, 10:21 AM
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; 
      } 
   } 

6 Answers, 1 is accepted

Sort by
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 24 Oct 2009, 10:27 AM
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 ?
0
xiaofeng
Top achievements
Rank 1
answered on 25 Oct 2009, 01:36 AM
Does your grid have gridviewimagecolumn ?You gave the solution about custom gridviewdatacolumn when we use Q2.
0
Missing User
answered on 25 Oct 2009, 08:41 AM

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.
0
Simon yang
Top achievements
Rank 1
answered on 26 Oct 2009, 01:36 AM
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!
0
Hristo
Telerik team
answered on 28 Oct 2009, 12:03 PM
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.
0
xiaofeng
Top achievements
Rank 1
answered on 03 Nov 2009, 03:37 AM
Hi!If I use the gridviewimagecolumn .How can I create a celltemplate in c#?Thank you!
Tags
GridView
Asked by
xiaofeng
Top achievements
Rank 1
Answers by
Ludovic Gerbault
Top achievements
Rank 1
xiaofeng
Top achievements
Rank 1
Missing User
Simon yang
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or