Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-24
5
Medium Priority
?
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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