How to insert the combo box inside DFatagrid in Silverlight - silverlight

I have to insert the combobox inside the DG in silverlight 4. And also it should be binded and the values inside

I don't think there is an "automatic" way to do this, unless you use some sort of custom third party grid. Otherwise, you'll need to define a custom column with the ComboBox as the template, and then on RowDataBind you can bind the data to the ComboBox ItemsSource property.
I found a post about this that has some examples.
Forum Post

Related

How can I apply AutoGenerateColumn to apply DataGridTemplateColumn.HeaderTemplate in a DataGrid?

for an overview, an MVVM project in built in WPF.
Basically in my xaml, I have a datagrid bound to a dataview. When my service populates the dataview I get a dynamic table with an arbitrary number of columns.
For each column in the datagrid, I have created a headertemplate which contains a combobox which is bound to an Observable<Dictionary<string,BusinessEntity>> object as its item source in the xaml. Figuring out the combobox is another issue but I am trying to just populate data grid first, then worry about binding the combobox correctly.
anyways the only solution I have somewhat though of was to turn on autogeneratecolumn and then replacing all the headers with a combobox in the codebehind, but then I have issues trying to bind the combobox in the codebehind correctly and it doesn't feel MVVM if I have to create all those comboboxes there.
You can handle the AutoGeneratingColumn event to customize the auto generated column's header template.

DataGridTemplateColumn Binding Using a TextBox in WPF with MVVM

I have a DataGrid that is bound to a List (ListOne). Inside the grid I'd like to display an extra TextBox that contains fields found in another Class that is not the same as the Class used in ListOne.
I've done this before with a ComboBox using the DataGridTemplateColumn, the problem is I'm not sure how the Binding would work when using a TextBox?
ListOne contains code and description which is bound and displays correctly. My SQL Stored Procedure returns extra values using a Join, which I'd like to display as editable fields ListOne.
Any ideas?
You should probably try to bind the DataGrid directly to the joined data as i imagine that doing joins directly in the cells may be difficult and round-about.

How to implement an editable listview in MVVM model?

I have an mvvm application...I need to have an editable listview.
I am binding my observable collection to listview.
How could I track changes of the values in listview ?...I mean if user edit an item...I need to have changed values in my observable collection.
If I use datagrid in WPFToolKit, is it easy ?
In a word, yes.
Take a look at data templates in WPF. They allow you to define how you want each item in your list (or any control) to appear and behave. So each item in your listview can one or more editable controls that are bound to each item in your collection (in this case an ObservableCollection). As you change data in the listview, the bound objects will in your collection will be updated in real time.
This is also possible with a datagrid.
Have a look at this link
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-3-in-place-edit
It is recommended you to use the Datagrid.It already provides the edit mode functionality. You can use a TemplateColumn to provide editing views.
if you have an editable Collection in your viewmodel, just take a datagrid(editable stuff built in). you can create styles or use templates so that the datagrid look the way you want.
If I use datagrid in WPFToolKit, is it easy ?
yes ;) but if you can, use the .net4 datagrid

how to extend wpf combo box to bind data?

i need to bind a collection of objects to a combo box which i can use in different forms. so i want create a custom control which binds the collection to the combo box? how t do it by extending combo box? also how can i define the ItemData template?
Why do you want to extend ComboBox? You can directly bind ComboBox to a collection using ItemsSource property! This and this page explains more about data binding and using ItemTemplate with ComboBox. Or, you can explore more on MSDN.

Silverlight AutoCompleteBox SelectedValue(?)

I need to implement an editable combobox where users can select existing values from the data/tables. It needs to be editable because users can also add new rows to the table by entering new values in the editable combobox, so I put an AutoCompleteBox control into my page but I can't find any sample on how to implement such feature. It should display something like Employee Name in the editable dropdown while having the SelectedValue property to contain the Employee ID.
Any help will be very much appreciated.
Cheers!
You will need to bind your autocompletebox's ItemsSource to your "lookup" collection.
You can use ValueMemberBinding to resolve the textual input to look for, ie if you have a list of people, bind this to Model.Name like this {Binding Name} to find people by name.
As far as the drop down items, you could use templating to display the items the way you like.
Heres a good tut on the subject, you want to style the ItemTemplate. following from the example you would make a datatemplate in xaml within the ItemsTemplate element add a Textblock and bind its Text property to Name like {Binding Name}.
Here a nice example where a autocompletebox is styled like a combobox. You could extend that to look for "enter" on TextChanged and check to see if the item is contained in the ItemsSource. If not it could push the new value to the server (if you are into MVVM, you could raise a command on you ViewModel that would delegate the addition to the server and update the Items).
Here's another example that extends the AutoCompleteBox to be used as a type-ahead ComboBox. It can handle foreign keys / lookup ids using DPs and can be used in MVVM scenarios.
AutoComplete ComboBox for Silverlight

Resources