Hello,
I bound data to Grid using DataSource property.
Then I call Grid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode);
but the problem is that I can not edit the cell value, its read only.
Thanks,
Yossy
I find the problem but I still do not know to solve it.
the problem is that my DataSource is a LINQ sentence like this:
orderby employee.LastName
select new { employee.LastName, employee.FirstName };
If I change to this code:
select employee;
Evrything is OK. But when I want to get only several fields I have the problem.
In fact I need to know how to change the DataSource characteristic so it will allowed updaing data even I only took several fields.
That's a c# feature. Selecting several fields uses the anonymous type feature in c# 2008, which creates a type with properties that have only get but not set. You can use the reflector to see the code of your assembly.
You have two options:
1. Create a new class that has two properties FirstName and LastName with get and set. Change the select to:
select new EmployeeName() { FirstName = employee.FirstName, LastName = employee.LastName }
2. Select the whole employee but hide the columns you don't need. You can do that in the grid designer.
I think the DataMember is not necessary in this case. Linq query returns an IEnumerable<T> where t is an Employee. You IEnumerable doesn't have a property named Employees (the BindingSource uses reflection to search the DataMember, so object is fine).
About your GetDataFunction, I suggest it won't return an object. Linq uses deffered loading, so only when the grid will show up, your query will be performed, and if your using Linq2Sql (the "db" is a DataContext?), you have to keep the DataContext and the SqlConnection alive.
I suggest you should wrap the linq query with a using statement, so the DataContext will be disposed at the end of the using block. Set the return type to "Employee[", and return employeeQuery.ToArray()
This approach is the only one that will work in an N-Tier system since you can't serialize the DataContext to the client application.
Shana Tova
Amiram, JCT
Hello jct.
I did already the second option you wrote, thanks.
another thing: i know that using this binding way:
ultraGrid1.DataSource = bs;
is better than using this way:
ultraGrid1.DataSource = employeeQuery;
But I have a new problem : I put the LINQ query in a function that return the results as an Object.
and when I tried to put the result in the BindingSource constractor like this:
BindingSource bs = new BindingSource(GetDataFunction("Emp"), "Employees");
I got an error the its not recognize the DataMember (the second parameter);
Thnks,