Solved

Is there any way to blank out repeating column-values in a WPF Linq-to-Entities query?

Posted on 2011-02-24
5
316 Views
Last Modified: 2012-05-11
Dear Experts
I am performing a Linq-to-Entities query into a DataGridView. I want the first column to display control-break values only. In other words it must look like this:

ValueA  Col2 Col3
ValueB  Col2 Col3
            Col2 Col3
            Col2 Col3
ValueC  Col2 Col3
            Col2 Col3
etc

If it is not possible to achieve this via a Linq query, please could you suggest a way to do it via a loop.
I have tried, but the compiler won't allow me to alter the DataGridView cell values.

Thanks and regards
Eddie

0
Comment
Question by:eddiecon
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Can you show me your LINQ query?  Are you using anonymous types, or are you using a list of "business objects" to bind to the DataGridView?  I can imagine a direction, but I would like to see what you have first...
0
 

Author Comment

by:eddiecon
Comment Utility
Thanks for responding.

The datagridview is bound to a datasource which is an entity model created from tables in a SQL database.

My LINQ query is very complex so I will give you a simplified version of it....

      Dim RoleQuery = _
         From a In DBcontext.ROLE_TABLE
         Join b In DBcontext.STAGE_TABLE On a.LIFECYCLE_CDE Equals b.LIFECYCLE_CDE
      Select Role = a.ROLE_NAME, Stage = b.STAGE_NAME

Thanks





0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
You should be able to convert that query into a list of business class (i.e. List(Of Role)), using the Select New With, and the ToList operators, as in this example:

Public Sub Linq()
   Dim words() = {"aPPLE", "BlUeBeRrY", "cHeRry"}
 
   Dim fruitList = (From w In words _
                    Select New Fruit With {.Upper = w.ToUpper(), .Lower = w.ToLower()}).ToList()
 
   For Each fruit In fruitList
       Console.WriteLine("Uppercase: " & fruit.Upper & ", Lowercase: " & fruit.Lower)
   Next
End Sub

Open in new window


Once you get a list of objects, you should be able to remove duplicates, before binding to the GridView.
0
 

Author Comment

by:eddiecon
Comment Utility
Thanks for your suggestion.
I changed my code to...

Dim RoleQuery = _
         From a In DBcontext.ROLE_TABLE
         Join b In DBcontext.STAGE_TABLE On a.LIFECYCLE_CDE Equals b.LIFECYCLE_CDE
      Select new with { .Role = a.ROLE_NAME, .Stage = b.STAGE_NAME }

      For Each RoleRow In RoleQuery
         RoleRow.Role &= " (testing)"
         RoleRow.Stage = ""
      Next
      DataGridView1.DataSource = RoleQuery

The For loop does not seem to change the values displayed in the DataGridView,
even though the debugger shows the RoleRow values changing correctly.

I get a syntax error if I put a variable name after "Select New" as per your Fruit example.
0
 

Author Comment

by:eddiecon
Comment Utility
Sorry!
I forgot the "toList()"

It's working great now.

Many thanks for your help!!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now