Good afternoon. I would just like to ask for your help on how to pass a value from the selecteditem of the RadGridView to a RadDataForm which is inside a childwindow. Basically, i have my main form wherein I have 2 RadDataGrid with 1 to many relationship. I have successfuly managed to add data to the 1st GridView and on the 2nd GridView. However, for the saving of data for the 2nd GridView, I need to include the KeyIDNo value from the 1st GridView for them to have a valid relationship.
I am using the following query from the DomainService of the application.
public void InsertTbl_rsdtls(tbl_rsdtls tbl_rsdtls)
{
tbl_rsdtls.rsdtls_date =DateTime.Now;
tbl_rsdtls.rsdtls_encodedby = "Place Username Here";
tbl_rsdtls.rsdtls_encodeddate = DateTime.Now;
tbl_rsdtls.rsdtls_modifiedby ="Place User Who Modified Record Here";
tbl_rsdtls.rsdtls_modifieddate = DateTime.Now;
if ((tbl_rsdtls.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(tbl_rsdtls, EntityState.Added);
}
else
{
this.ObjectContext.tbl_rsdtls.AddObject(tbl_rsdtls);
}
}
As you can see, I am also inserting additional details through this function call.
Now my question is, what is the best way to past the KeyIDNo of the SelectedItem from the 1st GridView to the RadDataForm in the Childwindow and then, how will I be able to save it. I am currently implementing a EF with a DomainServices.
Please also see attached screenshots.
Thanks in advance and hope someone can help me with my problem.
almond
14 Answers, 1 is accepted
You can get the parent from the first grid and assign it to the created detail. Then create a window and set its DataContex to the detail object. Set DataForm's CurrentItem to {Binding}.
Master master = parentGridView.SelectedItem
as
Master;
Detail detail =
new
Detail();
detail.Master = master;
ChildWindow window =
new
ChildWindow();
window.DataContext = detail;
window.Show();
Much thanks for your reply.
I forgot to say that I am a newbie with SL.
I would just like clarify that what i only need in the ParentGrid is the KeyID and all other information from the Childwindow will be saved in a Child/Detail table.I have also binded the other objects in TwoWay mode on the Child/Detail table as i will also be using the same ChildWindow in editting the record/s.
would it be alright if you can show me some codes or point me out where can i find a sample close to what I want to implement?
In some forums they are suggtesting to use View Model approach however as a newbie as I am, I am having a hard time understanding the View Model approach.
Thanks and hope someone can help me out with my problem.
regards,
almond
Instead of binding your dataform to a collection (setting the ItemsSource property) you can bind it to a single item (setting the CurrentItem property):
<telerik:RadDataForm CurrentItem="{Binding}" />
When a user clicks to add detail object, you create this detail in code and set its parent property to the selected item from the parent grid. Then you just set this detail to the DataContext property of the childwindow (the dataform will bind to this detail).
TheParent parent = parentGrid.SelectedItem as TheParent;
TheDetail detail = new TheDetail();
detail.TheParent = parent; //the detail already knows who its parent and gets parent id
YourChildWindow window = new YourChildWindow();
window.DataContex = detail;
window.Show();
And when a user clicks to edit an existing detail you don't have to create it. Just get it from the details grid:
TheDetail detail = detailsGrid.SelectedItem as TheDetail;
YourChildWindow window = new YourChildWindow();
window.DataContex = detail;
window.Show();
Thanks again Valentine.
Please see attached forms from the project.
By the way I am using a MySQL as database.
I cant seem to attached the project, please see my codes below:
DataSource Declarations for the Parent/Master Grid and the Details/Child Grid:
<!--RS Table-->
<
telerik:RadDomainDataSource
x:Name
=
"rsDS"
AutoLoad
=
"True"
QueryName
=
"GetTbl_rsIncByCompStatus"
DomainContext
=
"{StaticResource aimsDC}"
PageSize
=
"10"
Margin
=
"15,10,320,12"
Grid.Row
=
"1"
Grid.Column
=
"1"
LoadedData
=
"OnRSDataSourceLoadedData"
>
<
telerik:RadDomainDataSource.SortDescriptors
>
<
telerikData:SortDescriptor
Member
=
"rs_idno"
SortDirection
=
"Descending"
/>
</
telerik:RadDomainDataSource.SortDescriptors
>
<
telerik:RadDomainDataSource.QueryParameters
>
<
telerik:QueryParameter
ParameterName
=
"rsComp"
Value
=
"{Binding ElementName=CompanyText, Path=Text}"
/>
</
telerik:RadDomainDataSource.QueryParameters
>
</
telerik:RadDomainDataSource
>
<!--RS Details Table-->
<
telerik:RadDomainDataSource
x:Name
=
"rsDtlsDS"
AutoLoad
=
"False"
QueryName
=
"GetTbl_rsdtlsByIdNo"
DomainContext
=
"{StaticResource aimsDC}"
PageSize
=
"10"
Margin
=
"15,10,320,12"
Grid.Row
=
"1"
Grid.Column
=
"1"
>
<
telerik:RadDomainDataSource.QueryParameters
>
<
telerik:QueryParameter
ParameterName
=
"rsIDNo"
Value
=
"{Binding SelectedItem.rs_idno, ElementName=rsGridView}"
/>
</
telerik:RadDomainDataSource.QueryParameters
>
</
telerik:RadDomainDataSource
>
For the Parent Window with 2 RadDataFor Grid:
Here's the Declaration of the the Parent/Master Grid:
<
telerik:RadGridView
x:Name
=
"rsGridView"
MinHeight
=
"200"
MinWidth
=
"160"
CanUserFreezeColumns
=
"False"
RowIndicatorVisibility
=
"Collapsed"
ItemsSource
=
"{Binding DataView, ElementName=rsDS}"
IsReadOnly
=
"True"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"False"
Margin
=
"0,1,0,0"
OpacityMask
=
"Black"
AlternationCount
=
"2"
AlternateRowBackground
=
"#5AE8E8E8"
Grid.Column
=
"1"
SelectionChanged
=
"OnMasterGridViewSelectionChanged"
Height
=
"Auto"
VerticalAlignment
=
"Top"
AutoGeneratingColumn
=
"OnRadGridViewAutoGeneratingColumn"
FontFamily
=
"Verdana"
FontSize
=
"11"
>
<
telerik:RadGridView.Columns
>
<!--<telerik:GridViewToggleRowDetailsColumn/>-->
<
telerik:GridViewDataColumn
UniqueName
=
"rs_idno"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"ID"
DataMemberBinding
=
"{Binding rs_idno}"
IsVisible
=
"False"
/>
<
telerik:GridViewDataColumn
UniqueName
=
"rs_date"
Width
=
"90"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
DataFormatString
=
"{}{0:dd-MMM-yy}"
Header
=
"DATE"
DataMemberBinding
=
"{Binding rs_date}"
TextAlignment
=
"Right"
/>
<
telerik:GridViewDataColumn
UniqueName
=
"rs_company"
Width
=
"110"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"center"
Header
=
"COMPANY"
DataMemberBinding
=
"{Binding tbl_company.comp_abbr}"
TextAlignment
=
"Right"
/>
<
telerik:GridViewDataColumn
UniqueName
=
"rs_purpose"
Width
=
"250"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"PUPRPOSE"
DataMemberBinding
=
"{Binding rs_purpose}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
private void OnMasterGridViewSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
{
this.rsDtlsDS.AutoLoad = true;
}
<
telerik:RadGridView
x:Name
=
"rsDtlsGridView"
MinHeight
=
"200"
MinWidth
=
"200"
CanUserFreezeColumns
=
"False"
RowIndicatorVisibility
=
"Collapsed"
ItemsSource
=
"{Binding DataView, ElementName=rsDtlsDS}"
FontFamily
=
"Verdana"
FontSize
=
"11"
IsReadOnly
=
"True"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"False"
Margin
=
"1,1,0,0"
OpacityMask
=
"Black"
AlternationCount
=
"2"
AlternateRowBackground
=
"#5AE8E8E8"
Grid.Column
=
"1"
AutoGeneratingColumn
=
"OnRadGridViewAutoGeneratingColumn"
Height
=
"200"
VerticalAlignment
=
"Top"
>
<
telerik:RadGridView.Columns
>
<!--<telerik:GridViewToggleRowDetailsColumn/>-->
<
telerik:GridViewDataColumn
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"ID"
DataMemberBinding
=
"{Binding rs_idno}"
IsVisible
=
"False"
/>
<
telerik:GridViewDataColumn
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"ID"
DataMemberBinding
=
"{Binding rsdtls_idno}"
IsVisible
=
"False"
/>
<
telerik:GridViewDataColumn
Width
=
"60"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"QTY"
DataMemberBinding
=
"{Binding rsdtls_qty}"
TextAlignment
=
"Right"
/>
<
telerik:GridViewDataColumn
Width
=
"70"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"UNITS"
DataMemberBinding
=
"{Binding tbl_units.unt_desc}"
TextAlignment
=
"Right"
/>
<
telerik:GridViewDataColumn
Width
=
"400"
HeaderCellStyle
=
"{StaticResource gridHdrStyle}"
HeaderTextAlignment
=
"Center"
Header
=
"DESCRIPTION"
DataMemberBinding
=
"{Binding rsdtls_desc}"
TextAlignment
=
"Right"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
For the Parent/Master Grid. I have succesuflly implemented the add, edit and delete functionality. For the Child/Details Grid, I have also implemented the same if i dont take into consideration teh Parent/Master Grid's KeyID, but I need to save that ID in order for me to get the relationship of the two tables and have the Master Detail functionality to work.
Please see how I do my Childwindow Call for the addButton click of the Child/Detail Grid below:
private void addNewRSDtls_Click(object sender, RoutedEventArgs e)
{
//MessageBox.Show(rsGridView.SelectedItem.ToString());
RequisitionDtlsDataEntry addRsDtls = new RequisitionDtlsDataEntry("A");
addRsDtls.rsIDNoHldr = rsGridView.SelectedItem.ToString();
addRsDtls.Closed += new EventHandler(addNewRSDtls_Closed);
addRsDtls.Show();
}
void addNewRSDtls_Closed(object sender, EventArgs e)
{
//EmployeeRegistrationWindow emp = (EmployeeRegistrationWindow)sender;
RequisitionDtlsDataEntry rsDtls = (RequisitionDtlsDataEntry)sender;
//code can be deleted if it will not work.
if (rsDtls.newRsDtls != null)
{
aimsSysContext _aimsDomainContext = (aimsSysContext)(rsDtlsDS.DomainContext);
_aimsDomainContext.tbl_rsdtls.Add(rsDtls.newRsDtls);
this.rsDtlsDS.SubmitChanges();
}
}
Then, here my CodeBehind for the the ChildWindow:
namespace aimsSys2011.Views
{
public partial class RequisitionDtlsDataEntry : ChildWindow
{
public string rsIDNoHldr { get; set; }
public tbl_rsdtls newRsDtls { get; set; }
public string entryMode = "";
public RequisitionDtlsDataEntry(string _mode)
{
InitializeComponent();
entryMode = _mode;
switch (entryMode)
{
case "A":
newRsDtls = new tbl_rsdtls();
radDataFormRSDtls.CurrentItem = newRsDtls;
break;
case "E":
break;
case "D":
break;
default:
break;
}
radDataFormRSDtls.BeginEdit();
}
private void radDataFormRSDtls_EditEnded(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndedEventArgs e)
{
if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
{
radDataFormRSDtls.CommitEdit();
this.DialogResult = true;
}
else if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Cancel)
{
radDataFormRSDtls.CancelEdit();
this.DialogResult = false;
}
}
private void radDataFormRSDtls_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
{
if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
{
switch (MessageBox.Show("Are You Sure You Want to Save this New Record?", "Saving Requisition Details", MessageBoxButton.OKCancel))
{
case MessageBoxResult.OK:
try
{
if (((sender as RadDataForm).CurrentItem as tbl_rsdtls).rsdtls_itemcategory == null || ((sender as RadDataForm).CurrentItem as tbl_rsdtls).rsdtls_subcategory == null ||
((sender as RadDataForm).CurrentItem as tbl_rsdtls).rsdtls_type == null)
{
MessageBox.Show("Please Insert Values to Required Requisition Details.");
e.Cancel = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Alert!", MessageBoxButton.OK);
}
break;
}
}
else if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Cancel)
{
switch (MessageBox.Show("Are You Sure You Want to Cancel Adding/Editing Requisition Details?", "Cancelling Adding/Editing Requisition Details", MessageBoxButton.OKCancel))
{
case MessageBoxResult.OK:
try
{
switch (entryMode)
{
case "A":
newRsDtls = null;
break;
case "E":
//Console.WriteLine("Case 2");
break;
case "D":
//Console.WriteLine("Case 2");
//this.addSuppDataForm.ItemsSource = "{{Binding}}";
break;
default:
//Console.WriteLine("Default case");
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Alert!", MessageBoxButton.OK);
}
break;
}
}
}
private void itemCategoryCbo_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
MessageBox.Show(rsIDNoHldr.ToString());
}
}
}
<
telerik:RadDataForm
HorizontalAlignment
=
"Left"
Margin
=
"2,44,2,0"
Name
=
"radDataFormRSDtls"
VerticalAlignment
=
"Top"
CurrentItem
=
"{Binding}"
AutoCommit
=
"False"
AutoEdit
=
"True"
AutoGenerateFields
=
"False"
CommandButtonsVisibility
=
"Commit, Cancel"
Background
=
"{StaticResource Windows7RowBackground}"
EditEnding
=
"radDataFormRSDtls_EditEnding"
EditEnded
=
"radDataFormRSDtls_EditEnded"
Height
=
"340"
Width
=
"862"
>
<
telerik:RadDataForm.EditTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
Grid
x:Name
=
"DataFormGrid"
Margin
=
"2"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"40"
/>
<
RowDefinition
Height
=
"40"
/>
<
RowDefinition
Height
=
"40"
/>
<
RowDefinition
Height
=
"40"
/>
<
RowDefinition
Height
=
"40"
/>
<
RowDefinition
Height
=
"40"
/>
<
RowDefinition
Height
=
"40"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"107"
/>
<
ColumnDefinition
Width
=
"96"
/>
<
ColumnDefinition
Width
=
"56"
/>
<
ColumnDefinition
Width
=
"125"
/>
<
ColumnDefinition
Width
=
"12"
/>
<
ColumnDefinition
Width
=
"127"
/>
<
ColumnDefinition
Width
=
"330*"
/>
</
Grid.ColumnDefinitions
>
<
sdk:Label
Content
=
"Item Category: "
Height
=
"28"
HorizontalAlignment
=
"Right"
Name
=
"lblCompany"
VerticalAlignment
=
"Center"
Width
=
"89"
/>
<
sdk:Label
Content
=
"Item Type: "
Height
=
"28"
HorizontalAlignment
=
"Right"
Name
=
"lblPurpose"
VerticalAlignment
=
"Center"
Width
=
"66"
Grid.Row
=
"1"
/>
<
sdk:Label
Content
=
"Priority Details: "
Height
=
"28"
HorizontalAlignment
=
"Right"
Margin
=
"0,13,6,12"
Name
=
"lblRequestedBy"
VerticalAlignment
=
"Center"
Width
=
"91"
Grid.Row
=
"2"
/>
<
sdk:Label
Content
=
"Item Description: "
Height
=
"28"
HorizontalAlignment
=
"Right"
Name
=
"lblApprovedBy"
VerticalAlignment
=
"Center"
Width
=
"117"
Grid.Row
=
"3"
/>
<
sdk:Label
Content
=
"Quantity: "
Height
=
"28"
HorizontalAlignment
=
"Right"
Name
=
"lblNotedBy"
VerticalAlignment
=
"Center"
Width
=
"57"
Grid.Row
=
"4"
/>
<
sdk:Label
Content
=
"Status: "
Height
=
"28"
HorizontalAlignment
=
"Right"
Name
=
"lblPurchasingPer"
VerticalAlignment
=
"Center"
Width
=
"45"
Grid.Row
=
"5"
/>
<
sdk:Label
Content
=
"Miscellaneous: "
Name
=
"lblPurchasingPer_Copy"
Grid.Row
=
"6"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Right"
Height
=
"16"
/>
<
sdk:Label
Content
=
"Units: "
HorizontalAlignment
=
"Right"
Margin
=
"0,12,0,13"
Name
=
"lblNotedBy_Copy"
Width
=
"56"
Grid.Column
=
"2"
Grid.Row
=
"4"
/>
<
sdk:Label
Content
=
"For PO: "
HorizontalAlignment
=
"Right"
Margin
=
"0,11,0,16"
Name
=
"lblNotedBy_Copy1"
Width
=
"56"
Grid.Column
=
"2"
Grid.Row
=
"6"
Height
=
"13"
/>
<
sdk:Label
Content
=
"Item Sub Category: "
HorizontalAlignment
=
"Right"
Margin
=
"0,10,0,14"
Name
=
"lblCompany_Copy"
Grid.Column
=
"5"
/>
<
sdk:Label
Content
=
"Priority: "
HorizontalAlignment
=
"Right"
Margin
=
"0,13,0,11"
Name
=
"lblPurpose_Copy1"
Grid.Column
=
"5"
Grid.Row
=
"1"
/>
<
sdk:Label
Content
=
"Remarks: "
HorizontalAlignment
=
"Right"
Margin
=
"0,12,0,13"
Name
=
"lblPurpose_Copy2"
Grid.Column
=
"5"
Grid.Row
=
"4"
/>
<
ex:ComboBoxDataSource
x:Name
=
"CategoryDataSource"
DomainContext
=
"{StaticResource aimsDC}"
OperationName
=
"GetTbl_itemcategoryQuery"
Margin
=
"518,429,68,12"
/>
<!--<
ex:ComboBoxDataSource
x:Name
=
"subCategoryDataSource"
DomainContext
=
"{StaticResource aimsDC}"
OperationName
=
"GetTbl_itemsubcategoryQuery"
Margin
=
"578,429,12,12"
>
</
ex:ComboBoxDataSource
>-->
<
ex:ComboBoxDataSource
x:Name
=
"subCategoryDataSource"
DomainContext
=
"{StaticResource aimsDC}"
OperationName
=
"GetTbl_itemsubcategoryByIDQuery"
Margin
=
"578,429,12,12"
>
<
ex:ComboBoxDataSource.Parameters
>
<
ex:Parameter
ParameterName
=
"subCatItemIDNo"
Value
=
"{Binding SelectedIndex, ElementName=itemCategoryCbo}"
/>
</
ex:ComboBoxDataSource.Parameters
>
</
ex:ComboBoxDataSource
>
<
dataForm:DataField
Grid.ColumnSpan
=
"3"
Label
=
""
Margin
=
"3,3,0,2"
Grid.Column
=
"1"
Grid.Row
=
"1"
>
<
telerik:RadComboBox
x:Name
=
"itemTypeCbo"
DisplayMemberPath
=
"type_desc"
FlowDirection
=
"LeftToRight"
Grid.Column
=
"5"
Grid.Row
=
"0"
Height
=
"23"
HorizontalContentAlignment
=
"Left"
ItemsSource
=
"{Binding DataView, ElementName=itemTypeDS}"
Margin
=
"1,0,0,0"
SelectedValue
=
"{Binding rsdtls_type, Mode=TwoWay}"
SelectedValuePath
=
"type_idno"
ex:ComboBox.Mode
=
"AsyncEager"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Label
=
""
Margin
=
"3,3,0,2"
Grid.Column
=
"6"
Grid.Row
=
"1"
>
<
telerik:RadComboBox
x:Name
=
"priorityCbo"
DisplayMemberPath
=
"priority_desc"
FlowDirection
=
"LeftToRight"
Grid.Column
=
"5"
Grid.Row
=
"0"
Height
=
"23"
HorizontalContentAlignment
=
"Left"
ItemsSource
=
"{Binding DataView, ElementName=priorityDS}"
Margin
=
"1,0,0,0"
SelectedValue
=
"{Binding rsdtls_priority, Mode=TwoWay}"
SelectedValuePath
=
"priority_idno"
ex:ComboBox.Mode
=
"AsyncEager"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Grid.ColumnSpan
=
"6"
Label
=
""
Margin
=
"3,6,6,4"
Grid.Column
=
"1"
Grid.Row
=
"2"
>
<
telerik:RadMaskedTextBox
EmptyContent
=
"Please Input Priority Details Here..."
HorizontalAlignment
=
"Stretch"
MaskType
=
"None"
Name
=
"radMaskedPrioDtlsTxt"
SelectionOnFocus
=
"Default"
UpdateValueEvent
=
"PropertyChanged"
Value
=
"{Binding rsdtls_prioritydtls, Mode=TwoWay}"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Grid.ColumnSpan
=
"6"
Label
=
""
Margin
=
"3,5,6,6"
Grid.Column
=
"1"
Grid.Row
=
"3"
>
<
telerik:RadMaskedTextBox
EmptyContent
=
"Please Input Description Here..."
HorizontalAlignment
=
"Stretch"
MaskType
=
"None"
Name
=
"radMaskedDescTxt"
SelectionOnFocus
=
"Default"
Value
=
"{Binding rsdtls_desc, Mode=TwoWay}"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Label
=
""
Margin
=
"3,5,0,0"
Grid.Column
=
"1"
Grid.Row
=
"4"
>
<
telerik:RadMaskedTextBox
EmptyContent
=
"Qty."
HorizontalAlignment
=
"Stretch"
MaskType
=
"None"
Name
=
"radMaskedNotedByTxt"
ValueChanging
=
"radMaskedNotedByTxt_ValueChanging"
SelectionOnFocus
=
"Default"
Value
=
"{Binding rsdtls_qty, Mode=TwoWay}"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Label
=
""
Margin
=
"3,5,0,0"
Grid.Column
=
"3"
Grid.Row
=
"4"
>
<
telerik:RadComboBox
x:Name
=
"unitsCbo"
DisplayMemberPath
=
"unt_desc"
FlowDirection
=
"LeftToRight"
Grid.Column
=
"5"
Grid.Row
=
"0"
Height
=
"23"
HorizontalContentAlignment
=
"Left"
ItemsSource
=
"{Binding DataView, ElementName=unitsDS}"
Margin
=
"1,0,0,0"
SelectedValue
=
"{Binding rsdtls_units, Mode=TwoWay}"
SelectedValuePath
=
"unt_idno"
ex:ComboBox.Mode
=
"AsyncEager"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Grid.ColumnSpan
=
"3"
Label
=
""
Margin
=
"3,1,0,3"
Grid.Column
=
"1"
Grid.Row
=
"5"
>
<
telerik:RadComboBox
x:Name
=
"statusCbo"
DisplayMemberPath
=
"rs_stat_desc"
FlowDirection
=
"LeftToRight"
Grid.Column
=
"5"
Grid.Row
=
"0"
Height
=
"23"
HorizontalContentAlignment
=
"Left"
ItemsSource
=
"{Binding DataView, ElementName=rsDtlsStatusDS}"
Margin
=
"1,0,0,0"
SelectedValue
=
"{Binding rsdtls_status, Mode=TwoWay}"
SelectedValuePath
=
"rs_stat_id"
ex:ComboBox.Mode
=
"AsyncEager"
/>
</
dataForm:DataField
>
<
telerik:DataFormCheckBoxField
DataMemberBinding
=
"{Binding rsdtls_pogen, Converter={StaticResource MiscConverter}, Mode=TwoWay}"
FlowDirection
=
"LeftToRight"
HorizontalAlignment
=
"Left"
HorizontalContentAlignment
=
"Stretch"
Label
=
""
LabelPosition
=
"Beside"
Margin
=
"0"
Name
=
"forPOCheckBox"
Padding
=
"0"
VerticalAlignment
=
"Center"
VerticalContentAlignment
=
"Stretch"
Grid.Column
=
"3"
Grid.Row
=
"6"
/>
<
telerik:DataFormCheckBoxField
DataMemberBinding
=
"{Binding rsdtls_misc, Mode=TwoWay, Converter={StaticResource MiscConverter}}"
FlowDirection
=
"LeftToRight"
HorizontalAlignment
=
"Left"
HorizontalContentAlignment
=
"Center"
Label
=
""
LabelPosition
=
"Beside"
Margin
=
"0"
Name
=
"miscCheckBox"
Padding
=
"0"
VerticalAlignment
=
"Center"
VerticalContentAlignment
=
"Center"
Grid.Column
=
"1"
Grid.Row
=
"6"
/>
<
dataForm:DataField
Grid.RowSpan
=
"3"
Label
=
""
Margin
=
"3,3,6,8"
Grid.Column
=
"6"
Grid.Row
=
"4"
>
<
telerik:RadMaskedTextBox
EmptyContent
=
"Please Input Remarks Here..."
HorizontalAlignment
=
"Stretch"
Margin
=
"1,-40,3,-41"
MaskType
=
"None"
Name
=
"radMaskedNotedByTxt2"
SelectionOnFocus
=
"Default"
UpdateValueEvent
=
"PropertyChanged"
Value
=
"{Binding rsdtls_remarks, Mode=TwoWay}"
VerticalContentAlignment
=
"Stretch"
Padding
=
"2"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Label
=
""
Margin
=
"3,3,0,2"
Height
=
"36"
VerticalAlignment
=
"Top"
Grid.Column
=
"6"
Grid.RowSpan
=
"2"
>
<
telerik:RadComboBox
x:Name
=
"itemSubCategoryCbo"
DisplayMemberPath
=
"subcat_desc"
FlowDirection
=
"LeftToRight"
Grid.Column
=
"5"
Grid.Row
=
"0"
Height
=
"23"
HorizontalContentAlignment
=
"Left"
ItemsSource
=
"{Binding Data, ElementName=subCategoryDataSource}"
Margin
=
"1,0,0,0"
SelectedValue
=
"{Binding rsdtls_subcategory, Mode=TwoWay}"
SelectedValuePath
=
"subcat_idno"
ex:ComboBox.Mode
=
"AsyncEager"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Label
=
""
Margin
=
"3,6,5,4"
Grid.Column
=
"5"
Grid.Row
=
"5"
IsEnabled
=
"False"
>
<
telerik:RadMaskedTextBox
x:Name
=
"radMaskedRsIDNoTxt"
HorizontalAlignment
=
"Stretch"
MaskType
=
"None"
SelectionOnFocus
=
"Default"
UpdateValueEvent
=
"PropertyChanged"
Value
=
"{Binding rsIDNoHldr, Mode= OneWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}"
/>
</
dataForm:DataField
>
<
dataForm:DataField
Label
=
""
Margin
=
"3,3,0,2"
Grid.Column
=
"1"
Grid.ColumnSpan
=
"3"
>
<
telerik:RadComboBox
x:Name
=
"itemCategoryCbo"
DisplayMemberPath
=
"cat_desc"
FlowDirection
=
"LeftToRight"
Grid.Column
=
"5"
Grid.Row
=
"0"
Height
=
"23"
HorizontalContentAlignment
=
"Left"
ItemsSource
=
"{Binding Data, ElementName=CategoryDataSource}"
Margin
=
"1,0,0,0"
SelectedValue
=
"{Binding rsdtls_itemcategory, Mode=TwoWay}"
SelectedValuePath
=
"cat_idno"
ex:ComboBox.Mode
=
"AsyncEager"
SelectionChanged
=
"itemCategoryCbo_SelectionChanged"
/>
</
dataForm:DataField
>
</
Grid
>
</
StackPanel
>
</
DataTemplate
>
</
telerik:RadDataForm.EditTemplate
>
</
telerik:RadDataForm
>
Hope you can help me and thanks in advance.
almond
Can you help me adjust your code based on the objects that I sent you earlider.
I cant seem to understand where your objects TheParent and TheDetail came from.
Thanks again in advance.
almond
Will this work?
void addNewRSDtls_Closed(object sender, EventArgs e)
{
RequisitionDtlsDataEntry window = sender as RequisitionDtlsDataEntry;
tbl_rsdtls detail = window.radDataFormRSDtls.CurrentItem as tbl_rsdtls;
if(detail != null && detail.EntityState == System.ServiceModel.DomainServices.Client.EntityState.New)
{
tbl_rs parent = rsGridView.SelectedItem as tbl_rs;
detail.tbl_rs = parent;
}
if(rsDtlsDS.HasChanges) rsDtlsDS.SubmitChanges();
}
Hello Valentine,
Thank you so much for your help.
I was able to solve my problem basing on the code you sent.
As a newbie as I am, I found out with the help of your code that I can assign values to fields in the _Close function before I execute the .SubmitChanges
Basically I just added the code below:
rsDtls.newRsDtls.rs_idno = MyRSIDNoHldr;
and I was able to save the value of the KeyIDNo from the Parent/Master Grid. The MyRSIDNoHldr is a variable which I declared as long and was extracted from the rsGridView.SelectedItem.
For those who might have the same problem. Just message me and I'll be glad to help :)
Thanks again for your help.
I'm a newbie with silverlight. I have the same problem and wish you can help. I have a gridview in the parent page and a dataform in the childwindow. I pass the datacontext and currentitem to the childwindow's layoutroot and dataform control respectively. My problem is everything binds fine in the dataform only a combobox in the dataform is not displaying any selecteditem and it auto shows a validation error saying field is required whenever the the childwindow loads.
Hope you can help in this matter.
You may check this link: http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx
And then download the extension so that you can use it in your project. I was able to implement the functionality of the extension using the Telerik's RadComboBox .
You can also post your code so that we can check what caused the binding issue.
Thanks. :)
almond
Thank you so much for your prompt reply. The problem as I mentioned before is that the combobox field of the dataform in the childwindow is always blank and the correct Client Type is not selected eventhough the combobox is populated with with all Client Types. Here is my code wishing you can provide any help or advice.
Your help is much appreciated.
Public
Sub
pop_closed(sender
As
Object
, e
As
EventArgs)
Dim
chl
As
ClientSdfChild =
CType
(sender, ClientSdfChild)
If
chl.DialogResult =
True
Then
CType
(
Me
.LayoutRoot.DataContext, ClassClientContainer).Save()
Else
CType
(
Me
.LayoutRoot.DataContext, ClassClientContainer).Cancel()
End
If
End
Sub
Private
Sub
RadBtnEdit_Click(sender
As
System.
Object
, e
As
System.Windows.RoutedEventArgs)
Handles
RadButton1.Click
Dim
obj
As
New
ClientSdf
obj =
CType
(ClientSdfGrid.SelectedItem, ClientSdf)
Dim
pop
As
New
ClientSdfChild(obj.qClientCode, obj.qClientType)
AddHandler
pop.Closed,
AddressOf
pop_closed
CType
(pop.FindName(
"childWindow"
), Grid).DataContext =
Me
.LayoutRoot.DataContext
pop.Show()
End
Sub
Private
Sub
ClientSdfGrid_SelectionChanged(sender
As
Object
, e
As
Telerik.Windows.Controls.SelectionChangeEventArgs)
Handles
ClientSdfGrid.SelectionChanged
CType
(
Me
.LayoutRoot.DataContext, ClassClientContainer).CurrentClient =
CType
(
CType
(sender, RadGridView).SelectedItem, ClientSdf)
End
Sub
<
controls:ChildWindow
x:Class
=
"UnitReg.ClientSdfChild"
xmlns:controls
=
"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:data
=
"clr-namespace:UnitReg"
Width
=
"540"
Height
=
"658"
Title
=
"Client Details"
xmlns:sdk
=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable
=
"d"
xmlns:riaControls
=
"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:d
=
"http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:my
=
"clr-namespace:UnitReg"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
>
<
controls:ChildWindow.Resources
>
<
data:ClassClientContainer
x:Key
=
"ClassClientContainer"
/>
</
controls:ChildWindow.Resources
>
<
Grid
Name
=
"childWindow"
Width
=
"518"
Height
=
"618"
DataContext
=
"{Binding Source={StaticResource ClassClientContainer}, Path=CurrentClient}"
>
<
Grid.Resources
>
<
DataTemplate
x:Key
=
"MyTemplate"
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:DataFormDataField
Grid.Row
=
"0"
Label
=
"Client Code"
DataMemberBinding
=
"{Binding qClientCode, Mode=TwoWay}"
/>
<
telerik:DataFormComboBoxField
Grid.Column
=
"1"
Grid.Row
=
"0"
Label
=
"Client Type"
DataMemberBinding
=
"{Binding qClientType, Mode=TwoWay}"
ItemsSource
=
"{Binding Source={StaticResource ClassClientContainer}, Path=ClientTypes}"
DisplayMemberPath
=
"Description"
SelectedValuePath
=
"qClientType"
>
</
telerik:DataFormComboBoxField
>
<
telerik:DataFormDataField
Grid.Row
=
"1"
Label
=
"Acc Name"
DataMemberBinding
=
"{Binding ClientAccName, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Column
=
"1"
Grid.Row
=
"1"
Label
=
"Bank Acc. No."
DataMemberBinding
=
"{Binding BankAccountNo, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"2"
Label
=
"First Name"
DataMemberBinding
=
"{Binding Firstname, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"2"
Grid.Column
=
"1"
Label
=
"Last Name"
DataMemberBinding
=
"{Binding Surname, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"3"
Grid.Column
=
"1"
Label
=
"Client Category"
DataMemberBinding
=
"{Binding ClientCategory, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"3"
Grid.Column
=
"0"
Label
=
"Salutation"
DataMemberBinding
=
"{Binding Salutation, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"4"
Grid.Column
=
"1"
Label
=
"Other Name"
DataMemberBinding
=
"{Binding OtherName, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"4"
Grid.Column
=
"0"
Label
=
"IC Number"
DataMemberBinding
=
"{Binding ICNumber, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"5"
Grid.Column
=
"1"
Label
=
"Occupation"
DataMemberBinding
=
"{Binding Occupation, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"5"
Grid.Column
=
"0"
Label
=
"Tel"
DataMemberBinding
=
"{Binding Tel, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"6"
Grid.Column
=
"1"
Label
=
"Mobile"
DataMemberBinding
=
"{Binding Mobile, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"6"
Grid.Column
=
"0"
Label
=
"Email"
DataMemberBinding
=
"{Binding Email, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"7"
Grid.Column
=
"1"
Label
=
"Address"
DataMemberBinding
=
"{Binding Address, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"7"
Grid.Column
=
"0"
Label
=
"MailingAddress"
DataMemberBinding
=
"{Binding MailingAddress, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"8"
Grid.Column
=
"1"
Label
=
"RiskProfile"
DataMemberBinding
=
"{Binding RiskProfile, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"8"
Grid.Column
=
"0"
Label
=
"Password"
DataMemberBinding
=
"{Binding Password, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"9"
Grid.Column
=
"1"
Label
=
"Signature"
DataMemberBinding
=
"{Binding Signature, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"9"
Grid.Column
=
"0"
Label
=
"EPF Code"
DataMemberBinding
=
"{Binding EPFInvestmentCode, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"10"
Grid.Column
=
"1"
Label
=
"Client Status"
DataMemberBinding
=
"{Binding ClientStatus, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"10"
Grid.Column
=
"0"
Label
=
"MailingAddress"
DataMemberBinding
=
"{Binding MailingAddress, Mode=TwoWay}"
/>
<
telerik:DataFormDateField
Grid.Row
=
"11"
Grid.Column
=
"1"
Label
=
"Date of Birth"
DataMemberBinding
=
"{Binding DateOfBirth, Mode=TwoWay}"
/>
<
telerik:DataFormDateField
Grid.Row
=
"11"
Grid.Column
=
"0"
Label
=
"LastKeyInDate"
DataMemberBinding
=
"{Binding LastKeyInDate, Mode=TwoWay}"
/>
<
telerik:DataFormDateField
Grid.Row
=
"12"
Grid.Column
=
"0"
Label
=
"LastAppDate"
DataMemberBinding
=
"{Binding LastApprovedDate, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"12"
Grid.Column
=
"1"
Label
=
"LastApprovedBy"
DataMemberBinding
=
"{Binding LastApprovedBy, Mode=TwoWay}"
/>
</
Grid
>
</
DataTemplate
>
</
Grid.Resources
>
<
telerik:RadDataForm
HorizontalAlignment
=
"Left"
Margin
=
"12,12,0,0"
Name
=
"DF"
VerticalAlignment
=
"Top"
Height
=
"593"
Width
=
"494"
AutoEdit
=
"True"
AutoGenerateFields
=
"False"
ReadOnlyTemplate
=
"{StaticResource MyTemplate}"
EditTemplate
=
"{StaticResource MyTemplate}"
NewItemTemplate
=
"{StaticResource MyTemplate}"
CurrentItem
=
"{Binding Path=CurrentClient}"
>
</
telerik:RadDataForm
>
</
Grid
>
</
controls:ChildWindow
>
Public
Class
ClassClientContainer
Implements
INotifyPropertyChanged
Private
_Context
As
SdfDomainContext
Public
Sub
New
()
_Context =
New
SdfDomainContext
Clients = _Context.ClientSdfs
ClientTypes = _Context.ClientTypes
FilteredClients = _Context.ClientSdfs
End
Sub
Public
Event
PropertyChanged(sender
As
Object
, e
As
System.ComponentModel.PropertyChangedEventArgs)
Implements
System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected
Overridable
Sub
OnPropertyChanged(
ByVal
propName
As
String
)
RaiseEvent
PropertyChanged(
Me
,
New
PropertyChangedEventArgs(propName))
End
Sub
Private
_Clients
As
EntitySet(Of ClientSdf)
Public
Property
Clients()
As
EntitySet(Of ClientSdf)
Get
_Context.Load(_Context.GetClientSdfsQuery)
_Clients = _Context.ClientSdfs
Return
_Clients
End
Get
Set
(value
As
EntitySet(Of ClientSdf))
If
_Clients IsNot value
Then
_Clients = value
OnPropertyChanged(
"Clients"
)
End
If
End
Set
End
Property
Private
_ClientTypes
As
EntitySet(Of ClientType)
Public
Property
ClientTypes()
As
EntitySet(Of ClientType)
Get
_Context.Load(_Context.GetClientTypesQuery)
_ClientTypes = _Context.ClientTypes
Return
_ClientTypes
End
Get
Set
(value
As
EntitySet(Of ClientType))
If
_ClientTypes IsNot value
Then
_ClientTypes = value
OnPropertyChanged(
"ClientTypes"
)
End
If
End
Set
End
Property
Private
_CurrentClient
As
ClientSdf
Public
Property
CurrentClient
As
ClientSdf
Get
Return
_CurrentClient
End
Get
Set
(value
As
ClientSdf)
If
_CurrentClient IsNot value
Then
_CurrentClient = value
OnPropertyChanged(
"CurrentClient"
)
'FilterTypesByClient()
End
If
End
Set
End
Property
Please see how I implemented the
Add Reference:
xmlns:ex="clr-namespace:ComboBoxExtensions;assembly=ComboBoxExtensions"
Then add a DataSource:
<!--Item Type DS-->
<ex:ComboBoxDataSource x:Name="itemTypeDS" DomainContext="{StaticResource aimsDC}" OperationName="GetTbl_itemtypeQuery" Margin="518,429,68,12" />
Then add the Rad Combo Box:
<!--Item Type Combo Box-->
<dataForm:DataField Label="" Margin="3,3,0,2" Grid.Column="1">
<telerik:RadComboBox x:Name="itemTypeCbo" DisplayMemberPath="type_desc" FlowDirection="LeftToRight" Margin="1,0,0,0" Grid.Column="5" Grid.Row="0" Height="23" HorizontalContentAlignment="Left" ItemsSource="{Binding Data, ElementName=itemTypeDS}"
SelectedValue="{Binding rsdtls_type, Mode=TwoWay}"
SelectedValuePath="type_idno" TabIndex="1"
ex:ComboBox.Mode="AsyncEager" />
</dataForm:DataField>
Please always remember to place ex:ComboBox.Mode at the last part of declaration of the combobox.
Also, take note that the SelectedValuePath is the index of your Parent table related to a child table. On my side my parent table is the itemType with the index of type_idno which is related to the field rsdtls_type in my child table rsDtls. Then you will notice that in the DisplayMemberPath, I declared the type_desc field from the itemType table which will then display the description of the item type that was saved table.
Hope the code above will help you.
In the resources section of your child window you create a new ClassClientContainer object and it is different from that you pass to the grid's datacontext property in code. So you bind itemssource of your combobox to the wrong object.
I'm not sure if it will work, but you can try binding itemssource like this:
<
telerik:DataFormComboBoxField
DataMemberBinding
=
"{Binding qClientType, Mode=TwoWay}"
ItemsSource
=
"{Binding DataContext.ClientTypes, RelativeSource={RelativeSource AncestorType=Grid, AncestorLevel=2}}"
DisplayMemberPath
=
"Description"
SelectedValuePath
=
"qClientType"
/>
And I just noticed that you set the DataContext property of the grid both in XAML and in code... Set it in code only.
Thank you for your help. I tried the way you mentioned but it didn't work. I think the problem is not in the ItemsSource but in the DataMemberBinding. Because in my scenario sometimes when the childwindow first loads it shows the ClientType correctly but sometimes not and the validation for that combobox will be fired. I attached two screenshots of the both scenarios so you can understand my case.
Deeply appreciate your help.
<!--Status DS-->
<
telerik:RadDomainDataSource
Name
=
"serviceTypeStatusDS"
QueryName
=
"GetTbl_servicetypestatusQuery"
AutoLoad
=
"True"
DomainContext
=
"{StaticResource fsdbDC}"
>
</
telerik:RadDomainDataSource
>
<!--Status-->
<
TextBlock
Text
=
"Status: "
Margin
=
"2,0"
FontWeight
=
"Bold"
Grid.Row
=
"3"
Grid.Column
=
"1"
HorizontalAlignment
=
"Right"
VerticalAlignment
=
"Center"
Foreground
=
"#C14B4B4B"
/>
<
dataForm:DataField
Label
=
""
Grid.Column
=
"2"
Grid.Row
=
"3"
Margin
=
"3,3,0,3"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Center"
Width
=
"191"
>
<
telerik:RadComboBox
Width
=
"161"
Height
=
"23"
x:Name
=
"servTypeStatCbo"
SelectedValue
=
"{Binding servicetype_status, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}"
ItemsSource
=
"{Binding DataView, ElementName=serviceTypeStatusDS}"
SelectedValuePath
=
"servtypestat_idno"
DisplayMemberPath
=
"servtypestat_desc"
FlowDirection
=
"LeftToRight"
HorizontalContentAlignment
=
"Left"
Margin
=
"0"
Padding
=
"2,0"
/>
</
dataForm:DataField
>
You might want to check the relationship of your table as well.
Hope code above helps :)