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.
The two grids are in different files. What does setting missionRow["column name"] do? Does it not set the contents to what I pass in? How then does the grid get populated, from a List<T>? I have one object to fill the first grid because it has one row (master / detail). Do I have to put the one object into a List and then bind it? I tried using SetDataBinding(object, "Mission") but got an error "Child list for field Mission cannot be created".
Here are the properties of the data source:
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://ko.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.
Thank you for your help, I think we can mark this as resolved.
I can't explain any of the issues without seeing some code unfortunately. Let me know if you can send me any files.
I'm sure there are best practices and certain ways of doing things, but for now I'm just trying to get it to work enough to meet a deadline and I will improve it later.
Let me know where you are at and whether you need any further assistance.
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.