Solved

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

Posted on 2011-02-24
5
323 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 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] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 88
Problem to Office 1 62
Trouble installing msi file with msiexe.exe 2 43
Can Selenium do Load Testing? 2 56
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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 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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

742 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