Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection.
posted

<IG:XamDataGrid
x:Name="ResultsGrid"
MinHeight="200"
Margin="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutoFit="True"
DataSource="{Binding ResultSet, IsAsync=True}"
DockPanel.Dock="Top"
ActiveDataItem="{Binding Path=ActiveDataItem, Mode=OneWayToSource}"
Style="{DynamicResource StaticDataGridStyle}" >

<IG:XamDataGrid.FieldLayoutSettings>
<IG:FieldLayoutSettings
AutoGenerateFields="True"
FilterUIType="FilterRecord"
HighlightAlternateRecords="False"
AllowClipboardOperations="All"
SelectionTypeRecord="Extended"
HeaderPrefixAreaDisplayMode="FieldChooserButton"
CopyFieldLabelsToClipboard="True"
SelectionTypeCell="Single"
AutoFitMode="Never"
FixedRecordUIType="Button"
FixedRecordLimit="1"
AllowRecordFixing="Top"
FixedFieldUIType="Button"
/>
</IG:XamDataGrid.FieldLayoutSettings>
<IG:FieldSettings
AllowEdit="False"
SummaryUIType="MultiSelectForNumericsOnly"
SummaryDisplayArea= "BottomFixed,InGroupByRecords"
AllowRecordFiltering="True"
AutoSizeOptions="All"
AutoSizeScope="AllRecords"
AllowResize="True"
AllowFixing="Near"
/>

</IG:XamDataGrid>

public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}

private DataTable _resultSet = new DataTable();
public DataTable ResultSet
{
get { return _resultSet; }
set { _resultSet = value; OnPropertyChanged("ResultSet"); }
}

one one button click I'm addeing data in datasource 

_resultSet = new DataTable();
_resultSet.Columns.Add("Dosage", typeof(int));
_resultSet.Columns.Add("Drug", typeof(string));
_resultSet.Columns.Add("Patient", typeof(string));
_resultSet.Columns.Add("Date", typeof(DateTime));

// Here we add five DataRows.
_resultSet.Rows.Add(25, "Indocin", "David", DateTime.Now);

-- I'm getting this error on form load . 

Parents
No Data
Reply
  • 2490
    Offline posted

    Hello jit,

    Thank you for the code, you have sent. It was very helpful to observe the functionality you want to achieve.

    In order to avoid the exception which occurs on load you will have to specify the full path of the FieldSettings property:


    <IG:XamDataGrid.FieldSettings>
                        <IG:FieldSettings
                            AllowEdit="False"
                            SummaryUIType="MultiSelectForNumericsOnly"
                            SummaryDisplayArea= "BottomFixed,InGroupByRecords"
                            AllowRecordFiltering="True"
                            AutoSizeOptions="All"
                            AutoSizeScope="AllRecords"
                            AllowResize="True"
                            AllowFixing="Near"/>
    </IG:XamDataGrid.FieldSettings>

    Additionally, please note that you can add columns and rows to already existing table, if you want to change the DataSource, in this case by declaring a new table (_resultSet = new DataTable()), you will have to use ObservableCollection or a property which implements INotifyPropertyChanged, so consider using the property (ResultSet), rather than the field.

    For reference also see the attached sample application.

    XamDataGrid_AddDataTable.zip
Children
No Data