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
Hi,
I just wanted to know if you were able to solve your issue based on Mike's suggestions or you still need help? Just let me know.
Thank you.
Hi Hristo. Actually I went with a work-around that essentially loops through the first of the two datatables inside the dataset that I am binding to the grid to get my values and then adding them to labels above the grid.
In looking at previous responses I follow what Mike is saying, only the part about telling the grid which resultset I am binding to is not applicable in my case because the goal is to bind both datatables in the dataset (creating two bands) and use of a DataRelation to set the relational fields which is done my business object before the DataSet is returned.
Ideally though, if you guys have a good sample I can look at, that would be great in the event I have to deal these summaries on columns again. Also if the sample could include the SetDataBinding method implementation that would be helpful too.
Hello ,
I am glad to hear that you were able to find a solution for your issue.
If you isolate your issue in a small sample, in order to be able to reproduce it on my machine, I will try to find the exactly reason, which causes this issue and will be able to give you more specific and appropriate advices for improving of your code, if it could be improved.
I am waiting for your feedback.
Hi Hristo,
I am really not sure I undertand what you mean by isolating a small sample without sending you all of the code related to the operation that binds to the UltraGrid, save for just recommending you try the following:
1) Create DAL class and add a method that returns a DataSet - the method should call a stored procedure that consists of two select statements (select x from Products select y from ProductDetails)
2) Create Business Layer class that calls the DAL class, and method that returns the Dataset which itself returns a DataSet, but prior to returning the DataSet sets up a DataRelation object that associates the data in the first datatable inside the DataSet with the second datatable inside the same dataset, e.g.
public static DataSet getProductDetails(){
DataSet _ds;_ds = DAL.getProductDetails(); DataRelation dc = new DataRelation("ProductView", _ds.Tables[0].Columns["ProductID"], _ds.Tables[1].Columns["ProductID"], false);_ds.Relations.Add(dc);return _ds;}Assuming your Biz Class is called Product, at the UI level do the following in code (Assumes an Ultragrid has been defined in the form) and in the event most appropriate
protected void WinForm1_Load(.....){ugProducts.DataSource = Product.getProductDetails();}
Also add an InitializeLayout event for the grid ugProducts_InitializeLayout(sender, event)
And inside the Initialize_Layout method try adding one of the 1st or 2nd band's Columns to a Watch window, and specifically looking for the "Key" value in either band's columns - or try to read out the key of a given column and when hitting that line hover over it to see the value of the Key
In all my cases the "Key" s for all my columns are empty. I am doing nothing special to the UltraGrid just simple binding the control from a class method.
3)
Hello,
I am just checking about the progress of this issue. Let me know If you need any further assistance on this issue?
Thank you for using Infragistics Components.