Hello,
I am running into the issue described in the subject line. I have an UltraGrid in my WinForm application to which I bind a DataSet coming from a custom business object (e.g
gv.DataSource = BAL.Orders.GetAll()gv.DataBind();
)
The embedded Dataset that is returned has an embedded DataRelation object which associates an EmployeeID and ProcessingDate between the two tables that the DataSet contains and as such displays appropriately showing the first DataTable data in Band[0] and the second DataTable data in Band[1].
In the InitializeLayout Event however I am running into a problem where I am referencing a particular column in the grid (and that data in this particular column is not one of the data elements that make up the embedded DataRelation of the DataSet, but rather just one of the several columns that the first DataTable displays in the Grid band[0] columns) .
The issue I am encountering on build is an ArgumentException - was not handled. Key not foundParameter: key
.... when I make a reference to the column which I am setting up to use in a Summary in the Grid's header. Here is my code:
UltraGrid
gv = this.gvCompanyEarnedHours;UltraGridBand band0 = gvCompanyEarnedHours.DisplayLayout.Bands[0];UltraGridColumn colActual = band0.Columns["ActualHours"]; <-- Exception hereUltraGridColumn colEarned = band0.Columns["EarnedHours"];
//SummarySettings _settings1 = band0.Summaries.Add("SummedActual", SummaryType.Sum, colActual);//SummarySettings _settings2 = band0.Summaries.Add("SummedEarned", SummaryType.Sum, colEarned);// gv.DisplayLayout.Bands[0].Summaries["SumActual"].Appearance.TextHAlign = HAlign.Right;// gv.DisplayLayout.Bands[0].Summaries["SumActual"].DisplayFormat = "{0:###.#}";
I am at a loss here as to why it would be complaining about some missing parameter key? This has been an absolute shopstopper for me, short of pulling of my hair out.
Thanks,Paul
Hi Paul,
The exception indicates that band 0 in your grid does not contain a column with a key of "ActualHours".
So maybe this name is not quite right and doesn't match the actual column name in the data source. Have you tried looping through the Columns collection of Band0 to see what columns are actually there and what the keys are?
BTW, it is not neccessary to call DataBind on the grid. Setting the DataSource property implicitly does a DataBind for you, so this is redundant.
Also, are you setting the DataMember? It's not clear from the code here what the GetAll method is actually returning. But if it's returning a DataSet or some other IBindingListSource that can return more than one table, then the grid will bind to the first table returned by the data source unless you specify a DataMember.
In fact, if you need to specify both a DataSource and a DataMember, it's best to use the SetDataBinding method on the grid instead of setting the two properties individually. That way the gri doesn't bind twice.
Hi Mike,Thanks for the quick response. The method I mentioned is returning a DataSet containing 2 DataTables (see code below) (without the method signature):**********************************************************DataSet _dsEmployees;// Invoke DAL objectWorkGroupStatusBoardDAO dataObject = new WorkGroupStatusBoardDAO();_dsEmployees = dataObject.getWGSBEarnedHoursForEmployeeView(startDate, endDate);
DataRelation dc1;DataColumn[] parentCols;DataColumn[] childCols;
if (_dsEmployees != null && _dsEmployees.Tables.Count > 1)
{ parentCols =
new DataColumn[] {
_dsEmployees.Tables[0].Columns[
"EmployeeID"],
"LogicalDayDate"] };
childCols =
_dsEmployees.Tables[1].Columns[
dc1 =
new DataRelation("EmployeeEarnedHoursView1",
parentCols,
childCols,
false);
_dsEmployees.Relations.Add(dc1);
}
return _dsEmployees;
*****************************
Hence the Front End code gv.Datasource = MyObject.GetAll()
The method above calls my DAL object that in turns calls a stored procedure which returns two resultsets (two selects). The query within for the 1st resultset is using a Table variable which defines the field names (and the column name in question is the 7th field shown below)
Declare
@EmployeeStats TABLE
(
OID
int IDENTITY(1,1) PRIMARY KEY
EmployeeID varchar(20),
FirstName
varchar(20),
LastName
varchar(25),
LogicalDayDate
varchar(12),
AdjustedHours
float,
ActualHours
EarnedHours
Efficiency
float)
Insert into @EmployeeStatsSelect field1,field2,..... from and so on
Then the result of the first DataTable are read from the the @EmployeeStats table var-- 1st resultset Table[0]Select FirstName, LastName,LogicalDayDate, AdjustedHours,ActualHours,EarnedHours,Efficiency from @EmployeeStats
-- select results Table[1]select field1, 2, 3.... from .....
**********************************************
So all things considered I am bit confused about how it's not picking up the appropriate key. In fact when I view the column in the watch window the Key value is empty.
ANy ideas?
Thanks by the way for the tip on the DataSource/Databind - came over from the "web side" of the fence and wasn't aware of the difference in WinForm apps.
THanks,Paul