I have an ultra grid (C#) that gets bound to a dynamic dataset. I have a standard block of fields that are usually always there. Thus I account for them in the initalizelayout event and format them accordingly. Due to the dynamic nature of my data, sometimes extra columns get into the grid and of course since I don't know about them and haven't set them to be hidden....they show up on the grid. And of course use the SQL field name so that it definitely looks out of place.
Is there some setting or a way to hide all other fields that aren't explicitly defined?
Well, since you know the columns that you DO want to show, you could use the InitializeLayout event to loop through all of the columns and hide all the ones you don't want.
Also, you should check out the SetDataBinding method on the grid. There's an option third parameter which specifies whether columns that are not already defined should be hidden.
Also, take a look at the NewColumnLoadStyle property.
And finally, you may want to check out this KB article: HOWTO:How can I define columns in the grid at Design-time and bind them at run-time so that some fields of the data are excluded from the grid?
Mike--thanks for your reply.
Do you know of any examples that show looping through the columns in the InitializeLayout event? I do not use the designer to create my grids...does that affect anything?
Also, I ran into another scenario today that I thought I would ask you about. How would I check and work around a column that was defined in my InitializeLayout event, but now does not show up in the dataset (kind of the inverse of my original question)? I'm running into this scenario on a grid where on the initial load I need to give it an initial dump of data, but that dump is missing some of the fields that will be used going forward after the initial load. Currently I just use the AddRow method of the grid and loop through the dataset and just blank out the values of the columns I don't have data for.
Thanks again for your help.
skinpounder said:Do you know of any examples that show looping through the columns in the InitializeLayout event? I do not use the designer to create my grids...does that affect anything?
I'm sure there are examples of this all over the place. It's pretty simple.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { foreach (UltraGridBand band in e.Layout.Bands) { foreach (UltraGridColumn column in band.Columns) { switch (column.Key) { case "Key of a column I want to show": case "Key of another column I want to show": column.Hidden = false; break; default: column.Hidden = true; break; } } } }
This code loops through the bands. If you only have one band, you can skip the outer loop and just use e.Layout.Bands[0].Columns.
skinpounder said:Also, I ran into another scenario today that I thought I would ask you about. How would I check and work around a column that was defined in my InitializeLayout event, but now does not show up in the dataset (kind of the inverse of my original question)? I'm running into this scenario on a grid where on the initial load I need to give it an initial dump of data, but that dump is missing some of the fields that will be used going forward after the initial load. Currently I just use the AddRow method of the grid and loop through the dataset and just blank out the values of the columns I don't have data for.
I'm afraid I don't understand the question.