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

Can't export a grid row if any column of that row contains null value

1 Answer 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
saurabh
Top achievements
Rank 1
saurabh asked on 07 Jul 2010, 10:14 AM
we are using GridView control and we are trying to export data of Grid. But some columns of the rows contains null value, when we try to export it. It gives me some error. I attached a sample project. I got the following error message :

"Object Reference is Not set to an instacne of an object"
 

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            BuildSampleGrid();
            this.sampleGrid.ItemsSource = SampleGridItems;
           
        }

        /// <summary>
        /// Gets the Sample Grid Items
        /// </summary>
        public ObservableCollection<SampleGridItem> SampleGridItems { get; private set; }

        private void BuildSampleGrid()
        {
            this.SampleGridItems = new ObservableCollection<SampleGridItem>();

            this.SampleGridItems.Add(new SampleGridItem("John Smith", "123 Main St.","Deepak_agarwal@priyanet.com"));
            this.SampleGridItems.Add(new SampleGridItem("Mary Jones", "4050 N. Mountain Dr.","Deepak.agarwal1984@hotmail.com"));
            this.SampleGridItems.Add(new SampleGridItem("April Billings", "1 Hollywood Blvd.",string.Empty));
            this.SampleGridItems.Add(new SampleGridItem("Robert Basket", "98 Southern Pine Rd.",null));
           

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string extension = string.Empty;
            ExportFormat format = ExportFormat.Csv;

            extension = "csv";

            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt = extension,
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Csv"),
                FilterIndex = 1
            };

            if (dialog.ShowDialog() == true)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    sampleGrid.Export(
                        stream,
                        new GridViewExportOptions() { Format = format, ShowColumnHeaders = true, });
                }
            }
        }
    }

    public class SampleGridItem
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SampleGridItem"/> class.
        /// </summary>
        public SampleGridItem()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SampleGridItem"/> class.
        /// </summary>
        /// <param name="name">
        /// name as String
        /// </param>
        /// <param name="address">
        /// Address as String
        /// </param>
        public SampleGridItem(string name, string address,string eMail)
        {
            this.Name = name;
            this.Address = address;
            this.Email = eMail;
        }

        /// <summary>
        /// Gets the Name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets the Address
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// Gets the Address
        /// </summary>
        public string Email { get; set; }
    }

XAML Code:

 

 <Grid x:Name="LayoutRoot" Background="White">
        <telerikGrid:RadGridView x:Name="sampleGrid" HorizontalAlignment="Left"
                    AutoGenerateColumns="False" IsReadOnly="True" CanUserDeleteRows="False" CanUserInsertRows="False"
                    ShowGroupPanel="False" GridLinesVisibility="Horizontal" Width="341" CanUserFreezeColumns="False"
                    IsFilteringAllowed="False" ItemsSource="{Binding SampleGridItems}"
                    FontFamily="Arial"
                    FontSize="12"
                    Foreground="Green"
                    Background="{StaticResource ItemBackground}"
                                 AlternationCount="2"
                    AlternateRowBackground="Blue" OpacityMask="#FFC0CC58" RowStyle="{StaticResource GridViewRowStyle1}" Margin="0,0,0,181">
            <telerikGrid:RadGridView.Columns>
             <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name"/>
             <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Address}" Header="Address"/>
                <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Email}" Header="Email"/>
            </telerikGrid:RadGridView.Columns>
        </telerikGrid:RadGridView>
        <Button Content="Export" Height="50" Width="50" Click="Button_Click" Margin="347,1,3,249"></Button>
    </Grid>

1 Answer, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 07 Jul 2010, 01:43 PM
Hi saurabh,

 This problem seems to be fixed in our internal releases. The upcoming 2010 Q2 release, which should ship by the middle of the month will contain the fix.

All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
saurabh
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Share this question
or