Hello all,
I have the following scenario, we have a grid with many cols where we have text and icons.
The icons is added by using cell..Appearance.Image, and the text is the cell value (please see the image below).
Users want the option to filter by image, but keeping also the option to filter by text, is this possible to achieve?
Thank you so much
So, looking at your screen shot, you seem to have the same image applied to multiple values. So it's hard for me to answer your question because I don't know what criteria you are using for your images here. You cannot filter by an image, because images are not comparable. You cannot, in C# or VB compare one image to another - at least not in any easy or reasonable way.
So whatever fiter you were to apply here would have to be based on some kind of value in the cell or row.
Also, the user obviously has no way to enter an image into the filter cell via the keyboard - so the image would have to appear on the dropdown list.
So.. what you could do here is handle the BeforeRowFilterDropDownPopulate event (or possibly AfterRowFilterDropDownPopulate). This event gives you the ValueList that the grid shows for the filter list dropdown. You could add a couple of items to this list and assign whatever text you want and also the appropriate image. So the user could then pick an image from the list.
To perform the actual filtering, what you do is you create a class that derives from FitlerCondition and overrides the MeetsCriteria method. You assign this as the DataValue of the ValueListItem on the list. So when the user chooses that condition, MeetsCriteria on your FilterCondition will get called and you can decide whether the row meets the criteria or not - presumably using the same basic logic you are using to decide which image gets assigned to the appearance of the cell. I
m not 100% sure this will work, because I don't know if the filter cell will pick up the image when the user selects an item from the list that has an image on it. I think it will, but I could be wrong - in which case you might just have to make do with some descriptive text. I could probably whip up a sample for you, but it's really tough to do without knowing what kind of column this is and what the criteria for your images is. Is there a dropdown in this cell? Are you using the filter row? Are you using the UltraGridFilterUIProvider? If you could maybe post a sample that is representative of the correct data date, filtering, and images in your real grid, that would help a lot.
Hello Mike, thank you so mucho for your response.
Attached is a code example. As showed in the image the code example generates a grid with 2 could, Driver, it has a driver code in text and a Image, the what image is it displayed depends on the value for DriverImage, this second column will be hidden to the user. Now what I need to achieve is give the user the option to filter by that image but keeping the option to filter by the text too. It is not required to display the image in the filter with the other driver list values. Actually the filter could looks like this, where the images are represented by a description in text:
phase1
pase2
trainer
AZKX
XDDX
PIET
UJMD
UDJM
UltraGridExample.zip
Hi Amanda,
Okay, so this is a pretty simple case. I updated your sample to do what I described in my previous post. I created a class called ImageFilterCondition. This is a derived FilterCondition that is hard coded to operate on the DriverImage and look for a matching string. Then I handled the BeforeRowFilterDropDown event of the grid and watched for the Driver column and added one item to the list of each possible image string. So now the user can drop down the filter list and pick "phase1" and the grid will filter on rows whose DriverImage is "phase1", etc. I also applied to the images to the value list items.
The updated sample is attached here. Let me know if you have any questions.
5488.UltraGridExample.zip
Mike question, so the new FilterCondition logic will apply only for the customized filter options, all the other filter options no related with images will have the default behavior?
Yes, the derived FilterCondition is only used when you select one of those items from the list.You mentioned in your original post, allowing the user to type a string. To do that, you would need to change the FilterUIType to FilterRow instead of just using the header icons. But it would still only search the actual text of the column, not the DriverImage text.
Yes that is correct, it worked as expected. Just wanted to confirm. Thank you.
Hello,
I am glad that you managed to achieve your requirement.
Please do not hesitate to let us know if you have any further questions on this matter.
Regards,Teodosia HristodorovaAssociate Software Developer