I have a radgridview which is bound to an object that I created, foo.
Object foo has a property 'status' that is populated from an enum.
I have many foo objects stored in a collection, which I use to bind to my radgridview.
Upon binding I get records and the grid displays fine.
I'd like to not display the 'status' enum value from my foo object within the grid. Instead, I'd like to use separate images that will depict the status more clearly (and in less space). Example, if foo's 'status' enum value == Open, I will display an open door and value == Closed would be a closed door. So the same column could have different images, but from the same property bound by foo's status enum. Hopefully that's clear enough...
I have tried overriding the content value with a bitmapimage within the RowLoaded event of the grid. I have also tried setting the data type of the grid to image, butmapimage, and image source to no avail...
Seems like this should be much easier than it is... If the image came straight from the database, it wouldn't be a problem; there's plenty of examples out there. However, doing it dynamically AND through code remain a mystery.
Thanks in advance for any assitance!
Apparently all I needed was to post the question...
I fell victim to trying way too many things at once and a soultion that should have worked perfectly didn't because I was trying a style on a cell at the same time.
In the example provided above, within the grid's RowLoaded event, one could do the following:
Get the enum value from the cell content
Create an Image control ( System.Windows.Controls.Image img = new Image(); )
Assign the image's source depending upon the enum value ( open.png / closed.png )
Set the cell's content = to the image control you just created
When the grid displays, you should see your image in the grid cell...
You also need to ensure the column's datatype is set to:
typeof( System.Windows.Controls.Image )
Related
I am trying to use simple example code I've found in Google.
Everything works except as soon as I set the delegate for the column, it's displaying gets buggy.
Here are the line where I set the "Bank" string as a value for both rows and comboboxdelegate.cpp
Here's a screenshot of MainWindow
The question is, if the data is stored in model, why is it not displayed properly? Because if I change the value using combobox, what is displayed in cell still stays as shown in screenshot. However pressing button shows that data in model has been changed
P.S. I am not concerned about editor not being persistently visible, I'm concerned about displayed cell value being something else.
I had to change the line QString text = items[index.row()].c_str() to index.data(Qt::DisplayRole).toString().
So while painting the delegate Qt will access data stored in model, not in delegate's option vector
I also had to change model->setData(index, _editor->currentIndex()); to model->setData(index, _editor->currentText());
In my WinForms application, I have a GridGroupingControl where I need to display a certain data collection that has a rather complex structure.
The basic idea is that I want to have a combobox in one cell on each row, and that combobox has to contain a list that is defined for each row in the data collection.
Now my question is: How do I bind that specific list to the combobox in question?
My guess here is that I need to define this binding not on the column schema, but on the row schema in some way. How do I do this? I had guessed that I would add event handlers of the type "control.Row.DataBound" but I have not found any of the sort in this control.
NB: I come from a web development background, so my knowledge of Winforms is rather limited to begin with. Please bear that in mind when answering.
To insert a combo box in grid, you need to set the celltype as ComboBox and the data for combobox using ChoiceList. Please refer the below provided code snippet and KB’s for further clarification. The below code can be directly used in Form load or Constructor. If you want to set a specific cell as combobox cell then you need to set the cell type of that particular cell in QueryCellStyleInfo event (refer the kb’s for this).
Code Snippet:
this.gridGroupingControl1.TableDescriptor.Columns[1].Appearance.AnyRecordFieldCell.CellType= GridCellTypeName.ComboBox;
this.gridGroupingControl1.TableDescriptor.Columns[1].Appearance.AnyRecordFieldCell.ChoiceList = list1;
this.gridGroupingControl1.TableDescriptor.Columns[1].Appearance.AnyRecordFieldCell.CellValue = "Trial1";
KB links:
how-to-insert-a-combobox-in-a-header-cell-of-a-grid
how-to-change-the-dropdown-height-of-the-combobox-cell-dynamically
I'm using the Winforms PropertyGrid; the target of the SelectedObject includes a property of type Image. Everything is fine, except that with all items the same height, the image is too small to see properly. I'd like to have some control over the height of grid items such that the image can be displayed a bit larger. One other detail is that the SelectedObject of one PropertyGrid control may be assigned an object of any of a variety of different classes (which may or may not have image properties), so I'm hoping the height can be driven by data in the instance of the SelectedObject itself, rather than making it a static behavior of the control, although I'd settle for a custom attribute of the image property to make the item height at least class-specific if it can't be instance-specific.
How can I do this? Custom attribute? PropertyGrid event? Something else?
As Simon commented on your question, this is not possible to have a custom height for a GridItem.
You have 2 solutions to be able to show an image with a reasonable size:
You can code your own UITypeEditor. That way, the user would just click the down arrow and see a nicely sized image in the dropdown box.
Sorry for the plug but I think it directly answers your question: only 3rd party PropertyGrids may allow you to get variable size rows in the grid. Smart PropertyGrid.Net is one of them. You set a HeightMultiplier to the row so that it expands on let's say 4 rows. Then you code your own Look class that handles the drawing of the image the way you want in this space.
I'm using an ItemsControl that is populated with a collection containing several different data types. Each data type has its own DataTemplate, and they are all displaying correctly, but my problem is this: when there are several of the same type displayed one after another, the first one must display a header above it, and the last one must display a horizontal line below it. Is there a way to detect this in XAML, or do I need to pre-process this list a little to set flags?
The data is as follows:
Patient
Test
Result <-- header before this
Result
Result <-- line after this
Test
Result <-- header before, line after
Patient
Comment <-- header before this
Comment
Comment <-- line after this
Test
Result <-- header before, line after
I don't want to group the data types before displaying, they need to be displayed in the order in which they arrived.
You need to ask next/prevous sibling of each item about its type, and compare it with current item's type, and take into account that if both are equal and equal to the item, you do nothing... definitely you cannot do this with pure xaml.
Te easiest way to me would be to implement two bool properties in the viewmodel of the items 'HeaderVisible' and 'BottonLineVisible' and handle the logic there. Bind triggers to them in the DataTemplate to add top/bottom line as needed.
I think you would benefit from binding your ItemsControl to a resource key of a CollectionViewSource defined somewhere. You might be able to use the CollectionViewSource.GroupDescriptions[1] to show this in the UI.
Look at ItemsControl.GroupStyle[2] for how to style this.
[1] http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.groupdescriptions.aspx
[2] http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.groupstyle.aspx
I am facing a small problem using silver light . I have a RadGridView, with four columns. My second columns contains text boxes and the third column contains validation errors. If the third column contains validation errors, i want the second column background to turn red. How can i do this. I have tried binding the text box background column to a string with the desired color but that does not work. Really stuck here. Any help with be much appreciated.
Regards,
Mateen
Assuming your binding is otherwise valid, you cannot change colour by binding to a text string of a colour. The background property is of type Brush.
You need to either bind to a Brush instead, or use a brush/colour converter to return a Brush instead of a Color/string etc.
Try these links for converter examples:
http://forums.silverlight.net/p/20392/70263.aspx
http://forums.silverlight.net/p/20392/70263.aspx
You need a StringToObjectConverter found here. This class has the advantage that it has wider uses that eliminate the need to create a plethora of similar converters.
Further rather than having the bound object have a property called "Background" which tell the UI to "be red". I would be better that the Model had a property called "Status" which is an enum of the possible states the object is in.
Going further and looking at your specific requirement it would be better that your model exposed a boolean IsValid property which a converter could be applied to. See this blog on a generic BoolToValueConverter.