Hello everybody
I have a WinGrid which DataSource is made from a Linq Query. Everything works fine. Now, when I try to Format a Column like
e.Layout.Bands[0].Columns[
"ColumnName"].Format = "{0:##,##0.00}";
the Format ist not accepted. Following things I already tried:
It doesn't matter what I try, the Format is not accepted.
I am working with Infragistics Winforms 9.1
Thanks for help
Going by the code you pasted, you are setting the Format for a column named 'ColumnName', which I'm guessing is of type string. Formats are not applied to string data values.
Hello
The Column 'ColumnName' is actually of Type long. I tried first with the type long, then I casted the type of the Column 'ColumnName' to string. Neither was working.
I better let you know more about my code. The base of my datasource are two dataset. One dataset is filled from a SQL-Server 2005 Database. The other from an oracle database. To merge this two datasets I use the following linq-query:
//DataSet from SQL-Server
DataSet dsPlaene = this.auftrag.DBMethods.PlanSelectHochrechnung();
//DataSet from Oracle
DataSet dsBelegeH = this.auftrag.DBMethods.BelegeSumPerKostenart();
DataTable Plaene = dsPlaene.Tables[0].Copy();
Plaene.TableName = "Plaene";
DataTable BelegeH = dsBelegeH.Tables[0].Copy();
BelegeH.TableName = "Belege";
var Hochrechnung = from p in Plaene.AsEnumerable()
join bh in BelegeH.AsEnumerable()
on p.Field<string>("KostenartNummer") equals bh.Field<string>("KostenartNummer")
into g
from bh in g.DefaultIfEmpty()
select new
{
PlanID = p.Field<long>("PlanID"),
KostenartNummer = p.Field<string>("KostenartNummer"),
KostenartBezeichnung = p.Field<string>("KostenartBezeichnung"),
Gesamtkredit = p.Field<long>("Gesamtkredit"),
Budget = p.Field<long>("Budget"),
Ist = (bh == null ? 0 : bh.Field<decimal>("Betrag")),
Differenz = (p.Field<long>("Budget") - (bh == null ? 0 : bh.Field<decimal>("Betrag"))).ToString(),
Hochrechnung = p.Field<long>("Hochrechnung"),
Abweichung = p.Field<long>("Abweichung"),
AbweichungProzent = p.Field<long>("AbweichungProzent"),
Begruendung = p.Field<string>("HochrechnungBegruendung")};
//Convert Hochrechnung to a dataset
//Set the dataset 'datasetH' to the grid's DataSource
gridHochrechnung.DataSource = datasetH;
The Column 'Budget' should now be formated. So that's why I put the following could in the initialize_layout event:
e.Layout.Bands[0].Columns["Budget"].Format = "{0:##,##0.00}";
There is no further definitions for the column 'Budget'
If the grid has a normal (not merged with linq) dataset as its DataSource, everything works fine and the format will be accepted.
What wrong have I done. Please help
Thanks
The grid doesn't know or care where the data came from, it communicates with the binding manager. One thing you could do is check the DataType of the DataColumn that is generated for the 'Budget' column in each scenario and see what the difference, if any, is. If there is no difference, you can attach a simple sample here if you like and we can take a look.
I have attached a small sample (unzip in c:\Temp) with two examples in it. Example one works with two datasets and with linq. Example two bindes a simpla Dataset to the DataSource of the grid. Here you can see, that only Example two works properly. Example one behaves like described above. I also tried around with different formating strings, but it doesn't help.
Hope you can help me.
PS: I only have the possibility to work with linq, because I have two different datasources (SQL-Server, Oracle)
As I suspected, the data type of the column is string. The IEnumerable<T>.ToDataSet method is responsible for this; there might be some way to make it generate columns of a certain type, but I don't know how myself. I would just build the DataTable manually, i.e., add the columns and rows yourself.
On the basis of my small Example I posted last time, could you give me a coding sample, how to loop through the variable 'Query' to build up the DataTable
Thanks a lot
DataTable exposes a Columns collection and a Rows collection. You add members to the Columns collection to define the horizontal aspect of the table, and then add members to the Rows collection , with each cell's value corresponding to the column under which it appears. These collections expose the standard collection methods such as Add, Remove, and Clear...I'm sure there are several examples on MSDN which demonstrate how to manually populate a data table.