C# ultrawingrid v12.2
I have a grid, and at design time it has column headers.
I want to add a column filter on one column only.
After initialize_component, before binding any data at all, I have ...
instructionsGrid.DisplayLayout.Bands[0].Columns["LastUpdateDT"].AllowRowFiltering = DefaultableBoolean.True;
However, it comes back with the message Key not found: 'LastUpdateDate'. Parameter name: key ... basically, column count is 0.
Is there a reason why is column count is 0 when they exist at design time?
Thanks
Hi Carlos,
Looking at the code you had in your email, I noticed two things.
1. The column key that you used to set RowFiltering is “LastUpdateDT” while the error message says “LastUpdateDate” key not found. Are you using a different key?2. You said after intitalize_component and before binding any data the column count is 0. The column count will be 0 if you dint bind your grid with any data.
I suggest you to verify these two things first, and if I’m missing any details here can you please send them to me.
Sincerely,Sahaja KokkalagaddaAssociate Software Developer, Windows Formshttp://es.infragistics.com/
Thanks v much for your reply.
That was a typo, sorry - error message refers to LastUpdateDT.
So yes, you say the column count WILL be 0 of I don't bind the grid with any data.
Is this true then? Its just, at design time, the columns are there.
What I wanted to do is add a filter to one column only before data: bascially at runtime. And it's a date field.
Is this do-able? Is suspect it isn't. Thank you.
There are several solutions that I can think of depending on what your desired outcome is. In many of the cases I would recommend using the InitializeLayout event. It is designed to fire when you bind to the data. At that point the grid has the column definitions, but not the data itself. It will be there before your users get a chance to see or even interact with the UI. Which is ideal for most scenarios, as a filter is meaningless without data. But if you expect the UI to be open and in place for the user before the data is there, and you want columns in place before you have actual data. I would recommend either, temporarily binding to your data object, without data, in which case, you can still use InitializeLayout. Or you can add unbound columns, which should match to your data columns, and then when you bind to it any settings you have will stay in place. For the latter case make sure that your key's match or else they will not stay.
UltraGridColumn colName = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("name");colName.FilterConditions.Add(FilterComparisionOperator.Contains, "Bob");
this.ultraGrid1.DataSource = BuildData(new int[] { 10 });
Let me know if this works for your scenario,
Thanks very much, all very useful, I have decided to go with binding with an empty list and attached filter at that point.
Brilliant, thank you both, Sahaja and Michael