Solved

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

Posted on 2011-02-24
5
319 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Not showing JavaScript in the list 5 52
How would you add MULTITHREADING to the attached C# code? 4 62
SSRS troubles 4 46
REXEX help Part 2 2 22
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

816 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

7 Experts available now in Live!

Get 1:1 Help Now