I have a form with two tabs on it. One tab's UltraGrid is loading its data properly. The other tab, with a similar grid and code, is not loading its data. The data source has data in it, and I can see it being set to the UltraDataRow, however, it just won't show any data rows.
UltraDataRow missionRow = af664DataSource.Rows[0];// The data fields set here contain datamissionRow["To Date"] = fltRecAf664.MissionToDateTimeDt;missionRow["Aircraft Organization Home Station"] = fltRecAf664.TranBaseNameNm;missionRow["CMD"] = fltRecAf664.CmdCd;missionRow["MDS"] = fltRecAf664.MdsCd;missionRow["Serial Nbr"] = fltRecAf664.SerialNbr;
UltraGrid shows the columns, but no data rows (should be one row)
Is there a step I'm missing to have the data show up? I'm using similar code as the tab that is working and can't tell the difference and why it won't work.
Hello Sam,
Thank you for contacting Infragistics. How are you loading data? What datasource is used and when are the two grids binding? Can you reproduce the behavior? If so, please provide a sample demonstrating the behavior otherwise we will require a full designer.cs and/or code behind for the form to attempt to reproduce this on our end.
Sorry about the lack of detail. The data source is specified during design time, and the grid's data source property points to it. I'm new to this and I am maintaining a system that uses it. The other tab works fine, and I can't tell the difference between it and the tab that I'm working on. However, only the new tab is not loading data.
I see this in the designer of the first form (tab): this.missionGrid.DataSource = this.af781DataSource;
I see this in the designer of the second form (tab): this.missiongrid.DataSource = this.af664DataSource;
These are the only references to setting the data source that I can find.
Setting the column name is in a way just setting the column's key. It doesn't pass content. You need to set the UltraGrid's DataSource property.
There are a lots of examples on our online documentation about this:https://es.infragistics.com/help/winforms/wingrid-accessing-data
For creating custom data sources you can implement the .NET IList interface on your custom object. However, the IList interface doesn't support notifications for changes in data such as changes in cell values, adding or removing of rows, etc. Therefore if you want to support these operations in your data source then it is recommended that you implement the .NET IBindingList interface, instead, which has support for notifying the bound controls of such changes. Other interfaces that may be of interest are the .NET ITypedList and IEditableObject interfaces. Please consult the .NET Framework help for more information on these interfaces.
Setting DataSource or DataMember will cause the control to synchronously load the data source. Therefore if you need to set both of these at run-time, to prevent binding twice, use the SetDataBinding(Object,String,Boolean,Boolean) method instead of setting the individual properties. The SetDataBinding method lets you specify both pieces of information in a single call. Also note that since DataSource, DataMember and SetDataBinding all load the data source, there is no need to call the DataBind method.
If you set up your grid at design time with bands and columns and then bind at run-time to the actual data source, make sure that band and column keys match the names of the corresponding bands (relations) and columns in the actual data source. Otherwise settings on the bands and columns will not be carried over from design time. UltraGrid uses the keys (Key property) of the bands and columns to find matching bands and columns at run-time to copy over the settings from design-time. Therefore it's important to have the design-time band and column keys match the band (relation) and column names in the actual data source.
The same matching process is applied when changing the data source at run-time. The data structure of the control must match the data structure of the newly set data source. The control will automatically create all bands and columns exposed by the new data source. The control will try to maintain the settings on the existing columns and bands assuming that the Key of the Band is the same and that the Key of the column is the same. Columns or bands that do not exist in the new data structure will be destroyed and any new columns or bands in the new data source will be created. There is no way to prevent the the control from automatically picking up the new data structure - it must synchronize it's structure with that of the data source. However, you can make use of the UltraGridLayout.NewBandLoadStyle and UltraGridLayout.NewColumnLoadStyle properties to automatically hide new bands and columns in the new data source. Alternatively you can hide columns or bands by using the Hidden property of the appropriate object. Unbound columns will be maintained, so long as the band the column belongs to is not destroyed.
Thanks, I went with the instructions from Infragistics instead of trying to copy what was already done on the other form. It's still a work in progress, but hopefully it will start working.
Currently, after setting the grid data source to a List<T> it shows the column headers, but still no data. I don't know if I should define the columns in the data source beforehand, or let it figure out the columns from the List<T> collection. The grid looks weird, like something is behind the headers, but I can't tell what it is.
Great!
So normally the grid will never do that. I would start removing any appearances set in either code or the designer. You can click the grid in the designer and view the property window and see what is bolded. If you can't see any thing that might be triggering this then it could by a style loaded into the app, something we've developed called AppStyling. See if a stylist is loaded into the app. You can try turning off the UseAppStylist property on the grid to isolate this.
Using .ToArray() on the collection fixed the issue with binding the datasource. The data is still not showing up on either of the grids, but I'll keep working on it.
If you can provide a mockup of the data structure I can put together a small sample project. Have you tried the built in DataGridView to compare?
Clicking on the row or selecting another row turns it into a dark grey background and reveals the text. I set the ActiveRow to null, but it still selected the first row of each grid.
I removed any kind of resizing or other column manipulations and I got the data to show up. I also used SetDataBinding instead of DataSource. However, as you can see, the first row of each grid still has a black background.
I did a grid.Rows.Count() and it showed that the grids did have rows. They're just not displayed.
The first grid has one record, and the second grid has multiple records. There's no master/detail connection, it just loads all the data using the same FLT_REC_ID.