I have a radgridview with three columns: Company, Name, Status.
I want to try to prevent repeating instances of the company name when sorted by that column to avoid it showing the same company name over and over and over. Each row is bound to a single viewmodel where it gets its cell data from.
Is there anything I could use to accomplish this, so that a cell can check the cell in the same column in the row above it and if it's the same value, hide its own value so as to not repeat the same company name?
A suggestion would be to listen out for one of the Sorting or Sorted events and then you should be able to hide the data in some way. If nothing else I'd assume that you could use CellStyleSelector change the style of cells to have white text on a white background or something similar.
However, it might be worth asking Telerik themselves since I think they offer free help with these kinds of questions and they might have a better answer.
Related
I am planing to show hotel room booking status as a color effect. See the image. At want control I want to use?
Dude, this is WPF... you could use just about any control that you want to do that. Ok so I'm exaggerating a bit, but it really is your choice. You should use whatever you're comfortable with. However, if I had to design a UI that looked like your image, I'd probably either go with a ListBox or a DataGrid with a fairly high level of customisation.
If I were to use a DataGrid, the day names could be the column headers and the room names could be the row headers. You'd also need to use some sort of custom ColorConverter class to colour the cell data in the cells.
Using a ListBox, I'd create a DataTemplate to apply to the ListBox.ItemTemplate property that would contain the whole row including the room name. Of course, this would mean that you'd need to structure your data differently to include the name of each room. With a known number of days/columns, you could just use a Grid in the DataTemplate with the Grid.IsSharedSizeScope property set to True to keep the columns of each item aligned.
Good luck and have fun with that... it seems like an interesting project.
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 am developing a winform application application. I wanted to show sum of columns in last row of each column. This row must always be visible.
At moment I am thinking about adding another datagridview just beneath my datagridview with records, and would show the sum in that bottom datagridview.
If there is a better way to achieve this task?
No, need of adding another datagridview
Solution 1: Please refer to this solution
Solution 2: If the above link is not exactly what you want then,
You can try to manually add last, summary, row in which you can display information that you need. For example, you can try to do the following:
Read data from database and fill System.Data.DataTable
Add one column to the newly created DataTable – that column might be set
to true for the last, summary, row
Programmatically add one extra row that contains suitable summary data
Do the data binding to DataGridView control
Using appropriate event, bold or otherwise graphically distinct summary
row (row that have extra column value
set to true)
You can do it in the same way as you suggest, like placing a datagridview for displaying the sum. you can also handle the Horizontal Scroll with this, if there are more columns.
Another method is there in this link
Another way you can Add Rows to your datasource itself to display the sum.
Even if this question is quite old-ish I'd like to propose an extension to Niraj Doshis answer. His answer holds true for a data bound DataGridView. I recently had the problem to calculate the summary in a user-editable DataGridView, whose solution differs in the details. Anyway It's quite straight-forward too. I am writing my functions on a higher abstraction level, which outlines the workflow, but elides the implementation details.
First of all you'll have to initialize the DataGridView, see
private void InitializeDataGridView()
{
SetColumnTypes();
AddEmptyRow();
AddSummaryRow();
}
I set DataGridView.AllowUsersToAddRows to false for the new row would be located beneath the summary row. Hence I am adding an empty row, which the user may fill with his data. The summary row is set to ReadOnly since we do not want our user to edit it. Whenever a CellEndEdit is raised I am updating the DataGridView with the following method
private void UpdateDataGridView()
{
RemoveSummaryRow();
RemoveEmptyRows();
UpdateRowNumbers();
AddEmptyRow();
AddSummaryRow();
}
First I remove the summary and all empty rows (you'll have to take care. If you are trying to delete the row you just edited an exception will be thrown. I've not yet figured out how to do this, but I just made up the solution. I'll amend when I came up with the solution.) Afterwards I'm setting a running number in each of the rows. This is not really required, but a detail of my implementation. At the end I add an empty row again which the user may use to add further data and then calculate and add the summary row.
As I said before this is not yet a ready-made solution, but rather I concept which works but with some quirks and bugs.
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.)
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.