We are using UltraGrid, and on it we have applied some styling from .isl file. With that we have set TextHAlign="Left". But in the form we want to use TextHAlign="Center" for one column. We are achieving it by using below code in IntializeRow(object sender, InitializeRowEventArgs e) event. But once we mouse hover on this Cell, the Aligment is set to Left.
e.Row.Cells["MyColumn"].Appearance.TextHAlign = Infragistics.Win.HAlign.Center;
Please suggest the way how can we do it.
Screenshot:
Hi Narendra,
Yes, please, excuse that I missed on this requirement in preparing the last sample. You could omit the HotTracked state’s textHAlign=”Center” from the default StyleSet (in the sample) and use the InitializeRow to set the Column’s Cell Appearance TextHAlign property to left, as initially.
I have updated the sample to reflect this requirement. On my side it works as per the description of your requirement. Please, test it on your side and let me know how it behaves.
Best regards,Bozhidara Pachilova
2072.UGCellAlignment3.zip
I understand, but with this as well the required behavior won't achieved. Because we want the different alignment on a same grid. e.g. for "Column 0" we want left alignment, and for "Column 1", we want center alignment. And how can we set that?
Hello Narendra,
Thank you for sharing the .isl file markup.
As assumed, it is expected that the hover alignment of the cell is changed as the style file explicitly defines this.
After further investigation, I determined that there would be no straightforward way to programmatically override the HotTracked state settings, set by the style file on a particular grid. Actually, I found this forum thread, where the same question has already been discussed.
As per Mike’s suggestion, what you can do is create a new StyleSet in the isl file and set the BasedOn to the current StyleSet. Then, you have to copy the HotTracking settings that you want from the original StyleSet onto the new one - and reset those settings (so they are not set) on the original StyleSet). Then, the StyleSetName property could be set on the grids that should have the derived StyleSet applied:
private void Form1_Load(object sender, EventArgs e) { this.ultraGrid2.StyleSetName = "GridHotTracked"; }
In case a grid should use the default StyleSet, its StyleSetName property does not have to be explicitly set.
You could also set the “Normal” state alignment for the default/initial StyleSet to “Center” instead of programmatically overriding it in the InitializeRow event, as separating the StyleSets would allow this, and this will result in more maintainable style settings.
I hope these suggestions are helpful. Additionally, below you will find attached a modified version of the previous sample and .isl file, demonstrating this approach.
Best regards,Bozhidara PachilovaAssociate Software Developer
0624.UGCellAlignment2.zip
We are using below style in the .isl file:
<styles> <style role="GridCell" borderStyle="Solid"> <states> <state name="Normal" backColor="Transparent" foreColor="Black" borderColor="83, 83, 83" fontName="Segoe UI" textHAlign="Left" textVAlign="Center" borderAlpha="Opaque" fontSize="9" backGradientStyle="None" borderColor3DBase="Black" backHatchStyle="None" borderColor2="DarkGray" /> <state name="Selected" backColor="178, 178, 178" foreColor="Black" textHAlign="Left" textVAlign="Center" backGradientStyle="None" backHatchStyle="None" /> <state name="HotTracked" textHAlign="Left" textVAlign="Center"/> <state name="Active" backColor="178, 178, 178" foreColor="Black" borderColor="83, 83, 83" textHAlign="Left" textVAlign="Center" borderAlpha="Opaque" backGradientStyle="None" borderColor3DBase="Black" backHatchStyle="None" borderColor2="DarkGray" /> <state name="EditMode" backColor="178, 178, 178" fontName="Segoe UI" textHAlign="Left" textVAlign="Center" fontSize="9" backGradientStyle="None" backHatchStyle="None" /> <state name="ReadOnly" fontName="Segoe UI" textHAlign="Left" textVAlign="Center" fontSize="9" /> </states> </style> <style role="GridRow"> <states> <state name="Normal" textHAlign="Left" textVAlign="Center" /> <state name="AlternateItem" backColor="203, 214, 224" textHAlign="Left" textVAlign="Center" backGradientStyle="None" backHatchStyle="None" /> </states> </style> </styles>
We can't remove HotTracked property, because it's overriding property application wide. We need this in a specific form.
Thank you for posting to Infragistics Community!
I have been looking into your question and created a small sample with an UltraGrid of version 19.2 of Ultimate UI for WinForms as stated in the details of this case. The project loads an Infragistics Style File, containing a style, setting the GridCell role’s Normal state textHAlign property to “Left”. Then, as described by you, one of the columns’ TextHAlign is set n the InitializeRow event to HAlign.Center. However, I am only assuming that the style file is targeting the GridCell role. If this is not the case, please provide more details on how this is achieved.
On my side, everything works as expected and the overwritten alignment is persisted on hover. As the isolated sample shows the described features working correctly, this indicates that the issue is most probably local to your own project. Currently, I cannot tell for sure what may be causing this in your app, however, please make sure that the style file is not setting the alignment for the “HotTrakced” state of the GridCell as well.
In conclusion, please test the below attached sample on your side and let me know how it behaves.
0160.UGCellAlignment.zip