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.
Related
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!
I have a Silverlight Toolkit datagrid where one column shows textual representation of a numeric value. I would like to sort on the column's underlying numeric value but present the text data to the user. Values in the grid column are in a format such as:
A Category (200-300)
Some Category (100-200)
Yet Another Category (300-400)
As these values are textual the grid is correctly sorting on the text, however I have a custom Comparer which can already sort these by the numeric categories and would like to plug it into the grid.
The data-object that the grid cell is binding to only has the textual representation (and no way of easily adding the numeric value). Therefore, SortMemberPath= won't work in this case.
Is it possible to inject a custom comparer for a single grid column and sort on that? Or perhaps implement a CollectionViewSource with custom comparer? Remember this is Silverlight, not WPF so some fields/properties/classes are missing when compared to WPF.
The simplest way I feel to achieve this is to add two properties to entity that you are binding to grid one will be the text and the other can be numeric and binding only one to column of grid and other you can use in SortMemberPath. If not two properties you want to keep in entity then, you can keep Numeric only and use converter to convert it into text and SortMemberPath=NumericPropertyName.
I was wondering what the best way was to create an empty datagrid.
For example after you have hit new in excel, You have a grid with empty rows and columns.
I am using c# with WPF and .net 4.0.
Thank you.
As the comments have suggested, a datagrid is not a spreadsheet, but a method to display / edit existing data. That said if you want something similar, feel free to populate a collection with default / 'empty' objects and bind that to your grid. It just means that after working with the data, you will have to define a method to capture only the edited rows. This still means that the column-bound properties of your class need to be known ahead of time.
A DataGrid is used to display a collection. If you want to create an individual row DataGrid is not really the right tool. You could but a single empty row in the DataGrid using a collection of only on row. There is a lot of guidance on Master Detail on MSDN. If you don't know how many columns at design time you could used a DataGrid to turn the row vertical with column 1 as name and column as value so now you have one record but with a collection of fields.
I'm working on a new project where the design calls for dynamic rows and columns displayed in some form of grid. I think I can accomplish this very hackishly using the plain ol' Grid, but it seems like it should be possible using a "real" grid.
In my mockup, I circled the tricky bit in red. Under column 1, I have effectively 2 columns of data. The problem is the fact that my data in column 1 can span multiple rows. And the fact that column one is really two pseudo columns and each one can span a different number of rows independently. Note: the data is fake and inconsequential. I'm open to ideas for a good implementation. I can fall back to the Grid and do this all in code behind, I'm open to purchasing a datagrid that may have more power than the DataGrid and my absolute last resort/preference is to restructure this format to something a little more doable.
Thank you for any ideas you can provide.
Most commercial WPF DataGrid implementations handle hierarchical data like this. For example, Telerik's DataGrid (part of RadControls for WPF) supports hierarchical data in multiple formats.
Typically, the default styling is a bit different than yours above, but can be adapted to that format via styling.
I have a list of string array as input. The array dimension are static for all the list but I can't know the array size until the list is retrieved.
I need to bind the list in a datagrid in Silverlight.
I tried to create columns at runtime, binding each column to a particular array position but cannot find a way.
Have you any idea how to do it?
I could eventually "convert" my list of array in anything else that could be binded in a datagrid?
The idea is to have a sort of 2d Matrix showed inside the datagrid in Silverlight (I think that the problem is similar).
List
column_1 column_2 column_3 .. column_m
string[1,1] string[1,2] string[1,3] .. string[1,m]
string[2,1] string[2,2] string[2,3] .. string[2,m]
string[3,1] string[3,2] string[3,3] .. string[3,m]
....
string[n,1] string[n,2] string[n,3] .. string[n,m]
n is list lenght, m is list column max number.
Any idea is appreciated
I've found two solution to the problem that use the schema in the Denis's answer:
the first one is to use reflection to generate a class at runtime for the binding as suggested in this article (thanks to Vladimir Bodurov). I've tested this solution and I'll try to use it on my project. The only problem right now is that for large collection, the performance are poor. But I hope that someone will fix it in next relese (Silverlight 3 seems to not have fixed this problem, yet)
the second solution will be using some dynamic language for generate data. I don't know if this could be faster or not (probably not) but eventually could help. I will try in the future and use ironpython or ruby to generate classes that will be binded in datagrid.
If anyone have tryed using the second solution or any performance related information about creating classes at runtime, it will be appreciated.
Giorgio
Unfortunately that's not gonna be easy.
Do you have any valid constraints, like the maximum number of columns that is allowed or anything like that?
If you do (let's say you have N column maximum), you might be able to do something by
Having a class that exposes N
properties (named Col1...ColN for
example) that map the content
of the array for one line at column
X
Generating a list of that class,
one instance for each line
Generating the correct number of
column on the fly, binding each
column to property ColX
Binding your DataGrid to that list
That's kind of ugly, but it would work.
If you do not have to rely on the DataGrid, there is a possibility using a UniformGrid. A UniformGrid is a panel that layouts its children in a regular grid (every item has the same width, every item has the same height). You can indicate the number of columns at runtime, and the panel will fit children one after the other up to the number of columns and then continue on another line.
You could bind an ItemsControl to your array, indicating it should use a UniformGrid as its layout panel and indicating a suitable ItemTemplate to render each string.
The second option is much easier, but you will not have the capabilities of the DataGrid like sorting, moving columns, row selection, edition events per row etc.