Solved

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

Posted on 2011-02-24
5
320 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
ID: 34976425
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
ID: 34977829
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
ID: 34983516
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
ID: 34986784
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
ID: 34986796
Sorry!
I forgot the "toList()"

It's working great now.

Many thanks for your help!!!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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