Hello-
This post, even though it's old, suggests what I'd like to do should be possible:http://forums.infragistics.com/forums/p/5107/23272.aspx#23272
I've got an UltraGrid with two columns.
Column 0 is a UltraCombo loaded with a ValueList.Column 1 is a TextBox.
What I'd like to do is set the NullText property of column 1 whenever the value of column 0 changes.
Using that post above as a model, I've attached a new editor to the cell in column 1 as follows:
UltraTextEditor editor = new UltraTextEditor();((ISupportInitialize)editor).BeginInit();editor.NullText = "This is NullText";((ISupportInitialize)editor).EndInit();cell.EditorComponent = editor;
Unfortunately, "This is NullText" never displays even though the underlying value in column 1 is in fact null.
NOTE: "This is NullText" is just a test for this post. What I need to do eventually is assign editor.NullText a value that is associated with the value chosen from the dropdown in column 0.
First, although the above post SUGGESTS this is possible, is what I need to do possible?
If so, what have I done wrong with my code or how should this be handled differently?
Thank you.
If you want the NullText for each cell in column1 to change, all you have to do is handle the CellChange event, evaluate the value returned from e.Cell.Column to make sure it was a cell in column0 that has changed, and then set the new value of column1.NullText.
If you want a different value to be displayed for each cell, you could probably use an EditorWithText with a customized Infragistics.Win.UltraWinEditors.DefaultEditorOwner (one of the constructor overloads for EditorWithText takes an EmbeddableEditorOwnerBase, from which DefaultEditorOwner derives), and override the GetNullText method. In that method implementation you can conditionally return a different value for each cell if you like.
Correct, the goal is to get a different NullText value in the Column1 cell depending on the selection of the dropdown in Column0.
I've revamped my assignment of the Column1 editor (which occurs in the Column0 CellChange event) to this:
// UltraGridCell cell = Column1 Cell for the current rowEditorWithText editor = new EditorWithText(new TestDefaultEditorOwner());cell.Editor = editor;
where TestDefaultEditorOwner is:class TestDefaultEditorOwner : Infragistics.Win.UltraWinEditors.DefaultEditorOwner{ public TestDefaultEditorOwner() : base() { }
public override bool GetNullText(object ownerContext, out string nullText) { return base.GetNullText(ownerContext, out nullText); }}
I think I interpreted your suggestion properly but unfortunately TestDefaultEditorOwner.GetNullText(...) is never hit (in the debugger) and so I'll not be able to actually change the nullText here and have it affect anything.
Did I follow your suggestion properly?
If not, where did I go wrong?
If so, what have I missed doing that prevents the override GetNullText(...) from being called?
Thank you for your time.
Hi Robert,
I think you are on the right track here. But CellChange is probably not the best event to use. I think Brian mentioned it for the first option, but it doesn't really apply to his second suggestion of using a DefaultOwner. CellChange will only get fired if the user clicks into the cell and changes something. The event won't fire for any rows that were not modified by the user. So any rows that are in the DataSource initially, or any you add in code, will be wrong.
I'd use the InitializeRow event, instead. It will fire when the value of any cell in the row changes, as well as fire when the row is initially created, so it's perfect for what you need here.
I don't think this will currently work, though. Not every editor owner supports overriding every property using a DefaultOwner. If the grid already has a property for something that the editor normally handles, then the grid settings has to take precedence over the editor. Since the grid column already has a NullText property, it cannot look at the DefaultOwner.
But in fact, that's not true... the grid can look at the DefaultOwner provided that it knows whether or not it's own property was explicitly set. And in this case, I think it can know... but it's still not doing it.
This looks like a bug to me. So I'm going to forward this thread over to Infragistics Developer Support and have them write it up for developer review.
In the mean time, you could probably achieve what you want using a CreationFilter to set the Text of the TextUIElement in Cell 1.
Hi,
I have created a support ticket for you with id: CAS-52042-K5S1P0. I will update you about the progress of this issue there.
Regards,
Stefaniya
Mike- Thank you, I will give that a whirl. I've never done it so it might take me a bit to get there. Should I manage to come up with something particularly clever that actually works, I'll post it back here. There are 3 followers to this thread so it is interesting to more than just me I guess.
Stefaniya- Thank you, I'll watch the thread on the support ticket.
I appreciate everyone's time.
For any of the followers of this thread still following it, I've gotten part of the way there with the following.
I set the CreationFilter propery of my grid a new instance of MyCreationFilter defined thusly:
private class MyCreationFilter : Infragistics.Win.IUIElementCreationFilter { public void AfterCreateChildElements(UIElement parent) { if (!(parent is CellUIElement)) { // Parent element is not a cell element return; }
// Get the associated column UltraGridColumn column = parent.GetContext(typeof(UltraGridColumn)) as UltraGridColumn; if ((column == null) || column.Key != "ColumnThatShouldHaveNullText") { // Not the column we care about return; }
// Set null text according to value of the combobox in Cell0 column.NullText = "Hello World"; // This is Cell1 }
public bool BeforeCreateChildElements(UIElement parent) { return false; } }
This works ONLY in the sense that the NullText property of the cell is set but there doesn't seem to be a way to set it per the selected value of the CombBox in Cell0 so it's mostly useless for what I need.
If anyone has any advice to finish this up, I'd appreciate the contribution but this is about as far as I am able to go with it.
There hasn't been any action on the support ticket so I'm pretty much stymied with this.
Best Regards
You are almost there. There are just a couple of things I would change.
First, instead of watching for a CellUIElement, I would watch instead for a TextUIElementBase. Call GetAncestor on it to see if it's the child of a CellUIElement and then if you get one, do the same checks on the CellUIElement that you are doing now.
Second, setting the NullText property on column here isn't any better than how you were doing it before. That's not what you want. Instead, check the Value property on the cell. If it's null, then you set the TextUIElement's Text property to the null text you want displayed.
If you do as I suggested, you can set the text of the UIElement to any text you want. If you want to base that text on another cell in the same row, you can simply look at the value in the other cell and decide what text to use? What part of this are you getting stuck on?
Thanks for your time Mike.
I did try this approach but got no closer to the solution than I did with the small code in my previous post.
The problem is not just setting the NullText. Rather, the problem is setting the NullText for the Column1 cell based upon the ValueList selection from the Column0 cell.
The goal is to get a different NullText value in the Column1 cell depending on the selection of the dropdown in Column0.
Put another way from my original post, the null text I want displayed in the Cell in Column1 is dependent on the value selected from the UltraCombo in Column0. This null text value may be different for each row.
Maybe we're saying the same thing here but in all the information present in the arguments to the methods of IUIElementCreationFilter.AfterCreateChildElements, I've not yet found a way to get the value of a different cell (than the one being dealt with in this method) for the current row.
I hope this clarifies the problem. I'll take another shot at it later and if I magically figure it out, I'll post back here.