I have a Windows Form application where I need to represent in a DataGridView or ListView a list of items which consist of two label and an image. The text of the labels and the image depends on the property values of the object which the row refers to.
Reading many topics it seems that it's easier with the DataGridView defining a new type of column. I followed this topic and this ones but I can't reach the desired output.
Do you have any suggestions or idea?
Thanks!
Related
I have two lists of different object types in my ViewModel. For example I'd say the first one is a list of all available images, the second one is a list of all articles. Each article belongs to an article category for which I'd like to show a thumbnail in the GUI when an article is selected and shown. For the sake of a simple example I assume that the Id of the category equals the Id of the corresponding image.
For a ComboBox this would be an easy task: I would assing the list of all images as ItemSource and then the article's category key to the SelectedValue. The SelectedValuePath would have to point to the Id of the image.
However a ComboBox does not make sense here as I only want to display the correct category image - I do not want any editing, a dropdown, etc... How would I solve this with a regular Image-UserControl (or maybe a similar UserContro)?
BTW: Right now I have to use an additional Property on my Article class which directly holds the correct image, but I think there should be a better way to solve this issue.
Any ideas?
Regards
ralf
There's no problem with creating a get-only property on your ViewModel that provides the image that the view should bind to. The whole point of ViewModels is to shape model data into a structure suitable for binding views to.
I have an desktop WPF application that shows values from different files, the objective being to compare those files. The values extracted from the files are displayed in a DataGrid, one column per file. The user can add or remove files at will, which means that the amount of columns displayed in the grid can change. Columns are created and removed from a ViewModel, and have complex content that requires the use of DataGridTemplateColumn instances.
The data source is basically a two dimentionnal array (something like ObservableCollection<ObservableCollection<CellViewModel>>).
To fill my cells I need a data template, but the problem is that the DataTemplate's data source will be the row. And if I want to display the correct value, I'll have to know the index of the current cell from the template, so I access the correct index in my row. In the end, I'd like to be able to have a binding in the template that looks like {Binding Path=[someIndex].DisplayText} (DisplayText being a property of my CellViewModel).
I hope I've been clear enough :)
So the question is : how do I read the correct index in my row from the template ? Or, is there some better way to handle this variable-sized templated columns list problem ?
Thanks
I am filling up a Stackpanel with Textboxes. Each textbox, Should display the Value Property of a Class i have written.
The number of Textboxes is always different so i can't create a databinding in the xaml file.
Are there tutorials, that show how can i archive my goal?
Edit: Thanks for the replies so far. After reading the articles i still not clear how to implement my Problem.
Here is what I'm trying to achieve:
I have an SQL Server DB and there a Table with an ID and a Value.
I now load all Values and IDs i want to display into my application. (number of loaded rows is always differnt).
I need to display a textbox for each row and display the value there and after the value is changed i write the value back to the database.
I don't know how I should query the data and than bind it to the textboxes.
I don't need an implementations, I am happy with every piece of advice I can get.
yes there are a number of tutorials out there. It sound like you are interested in datatemplating.
I would suggest looking Here on MSDN. A few tutorials on databinding in general may be useful DataBinding on MSDN
If your class, classValue, has a public property Value then just create a List and bind that to a ListBox with the item DisplayValuePath = Value. Repeater controls are used to bind to collections.
Here is what I want to achieve:
I have RadGridView, let's call it gridView, with two columns - first contains ordinary text (GridViewDataColumn), second is a GridViewComboBoxColumn. Each row consist of property (first column) and possible values (displayed in comboBox in second column) which vary for each property. For example:
Property: border
Possible values: solid, dash
Property: font-family
Possible values: arial, times new roman
The problem is that I can set data source for whole column but not for individual ComboBoxes - or at least I don't know these controls good enough.
Data is bound correctly, but the only thing missing is separate data source for each comboBox. How to achieve that?
I'm using Silverlight 4, Telerik controls Q1 2010 SP2
Vlad's comment contained solution to problem:
You can use GridViewComboBoxColumn ItemsSourceBinding to achieve this - different source for each combo. Thanks.
I know there has to be an easy way to do this, I just can't think of it. I need to display a set of notes in a WPF application. The layout for each note would be
Note Name Note Date
Note Text
Each item above exists individually in my database access layer and I just need a way to display it. In ASP, this is something I might have created a table for and then used the repeater object to dislay it multiple times (multiple notes).
Is the ListView control the best way to go about this? How would I display multiple items next to each other as above with the NoteName and NoteDate?
You could use a ListView. In this case you would declare a GridViewColumn for each column, with the appropriate DisplayMemberBinding or CellTemplate depending on the complexity of what you wanted to show.
You could also use an ItemsControl or a ListBox, with an appropriate DataTemplate. This is good for when you do not want a strict column layout (e.g. you want to show the Name and Date on one line of big bold text, and the Note Text below that in smaller italic text.)