i have a xamDatagrid set up as follows :
<igDP:XamDataGrid DataSource="{Binding}" x:Name="xamContact" >
<igDP:XamDataGrid.FieldLayouts> <
igDP:FieldLayout>
<igDP:Field Name="DepartmentName" Label="Department Name" />
<igDP:Field Name="FirstName" Width="100" Label="First Name" />
<igDP:Field Name="LastName" Label="Last Name" />
<igDP:Field Name="RoleName" Label="Role Name" />
<igDP:ComboBoxField Name="Contactby" Visibility="Visible"
ItemsSource="{Binding}" Label="Contactby">igDP:ComboBoxField>
<igDP:Field Name="ContactType" Label="ContactType" Visibility="Collapsed" /> igDP:FieldLayout>
igDP:XamDataGrid.FieldLayouts>
in the code behind i want populate the xamDataGrid included the ComboBox field"Contactby"(situated in the xamDataGrid) as follows:
public DataTable GetContTable()
{ DataTable tableCont = new DataTable();
tableCont.Columns.Add("DepartmentName", typeof(string));
tableCont.Columns.Add("FirstName", typeof(string));
tableCont.Columns.Add("LastName", typeof(string));
tableCont.Columns.Add("RoleName", typeof(string));
tableCont.Columns.Add("Contactby", typeof(object));
tableCont.Columns.Add("ContactType", typeof(string));
tableCont.Columns[5].ColumnMapping = MappingType.Hidden;
// tableCont.Columns[4].ColumnMapping = MappingType.Hidden;
return tableCont; }
public void AddRowsCont(DataTable dtcont)
{ string[] card = new string[1000];
for (int i = 0; i < lstContactBy.Items.Count; i++)// there are 3 items in this listbox as follow "PLANNING","RESERVATION","ASSISTANCE"
{ card[i] = lstContactBy.Items[i].ToString(); }
dtcont.Rows.Add(txtDepartment.Text, txtFirstName.Text, txtlastName.Text, txtROlename.Text,card ,"SKYPE"); }
//here is the button to insert the data in the x
amfdatagrid AddRowsCont(tableCont);
xamContact.DataSource = tableCont.DefaultView;
the result is the xamdatagrid can be populate instead the ComboBox "Contactby" is populate only with a message'String[] Array' How i can populate also the ComboBox with the three items without error?
Thanks a lot
Hello gerryjj,
Thank you for the clarification of what you are looking to achieve.
Currently, in the Infragistics suite of controls in WPF there are two XamComboEditors - a WPF specific one that exists in the Infragistics.Windows.Editors namespace, and a shared (compatible with WPF and Silverlight) one that exists in the Infragistics.Controls.Editors namespace. The WPF-specific one currently does not support multiple-selection, which unfortunately is the one that the XamDataGrid uses for the ComboBoxField, so I don't believe this behavior you are looking to achieve will be easily obtainable using the ComboBoxField in the XamDataGrid.
Instead, I would recommend leaning towards another option. I would recommend writing a Style for CellValuePresenter and setting the ContentTemplate of this style to the shared XamComboEditor, which supports multiple selection. Then, you can place this CellValuePresenter style on a XamDataGrid Field by utilizing the Field.CellValuePresenterStyle property. Since the data type of this Field will be of a collection type, you may want to consider using an AlternateBinding as well, as your Field may show up in a child level because the collection will be interpreted by the grid as a hierarchy.
Going back to the shared XamComboEditor, in the CellValuePresenterStyle, the CellValuePresenter has a reference to the data item, as the data context of the cell is the data record that that particular cell belongs to. The shared XamComboEditor has a SelectedItems collection, which can be bound to an ObservableCollection<object>. So, if you bind this SelectedItems property to the CellValuePresenter's Record.DataItem.PropertyName via a RelativeSource binding, you can have your underlying data item update when selecting new items. I did find a slight issue with this, in that the SelectedItems binding does not seem to want to take effect on the initial load of the grid, and so I would recommend handling the Loaded event of the XamComboEditor and setting the SelectedItems property there.
I have attached a modified version of the original sample project I had sent you to demonstrate the above. I hope this helps you. Also, just as a heads up, there have been other Infragistics forum threads that discuss a very similar issue to this one. You can view these other forum threads here and here.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Dear Andrew,
thank so much for your kind reply...
what i am looking is everytime i add a new row in the xamdatagrid for each row the combobox field has a different values ,these values are binding from checkcombobox as follows :
Contacts = new List<ContactBy>(); Contacts.Add(new ContactBy("CONTRACT")); Contacts.Add(new ContactBy("PLANNING-BO")); Contacts.Add(new ContactBy("PLANNING-FO")); Contacts.Add(new ContactBy("RESERVATION")); Contacts.Add(new ContactBy("LOGISTIC")); Contacts.Add(new ContactBy("COST-CONTROL")); Contacts.Add(new ContactBy("ACCOUNTANCY")); this.cmbContactBy.ItemsSource = Contacts.ToList(); //xamcheckcombo that allow AllowMultipleSelection
so each time i add a new row the combobox (inside the xamdatagrid) will change values .
Let me know if it is clear or i will give you more details.
Thanks so much
Cheers
Thank you for your post!
I am a little bit unsure of what you are asking, but from what I understand, inside of the "ContactBy" column you have placed a ListBox as the row value and are looking to populate a ComboBoxField in the XamDataGrid with the values that exist inside of that ListBox. Is this a correct impression on this matter? If it isn't, please let me know.
If the above impression is correct, I would recommend that you obtain your ComboBoxField in code and set the ItemsSource of it there, rather than binding it. The fields in a XamDataGrid do not expose a data context property, as they don't exist in the visual tree of the grid. This makes it rather difficult to bind their dependency properties via bindings of the type {Binding Path}. If you do this in code, you can obtain the ComboBoxField from the XamDataGrid.FieldLayouts[field layout index].Fields[field name] collection, and set it to a new List<string> which you can populate with the items that exist in your ListBox as shown above.
Judging by the line that you have provided reading dtcont.rows.Add(txtDepartment.Text, txtFirstName.Text, txtlastName.Text, txtRolename.Text, card, "SKYPE"), it appears that you are adding a string array to each row of your DataTable. This will display an array in your XamDataGrid. Is this what you are looking to display, or are you looking to display only a single value per field, and have the array of strings be your ItemsSource for you ComboBoxField? If it is the latter, I have attached a sample project demonstrating the usage of a ComboBoxField in that way. If not, would it be possible for you to please provide some more detail on the behavior you are looking to achieve?
The sample project demonstrating the usage of the ComboBoxField in the XamDataGrid is attached.