|
|
Issue when binding custom column with DataGridView
Last post 07-02-2008, 1:08 AM by dguaraglia. 10 replies.
-
07-01-2008, 3:50 AM |
-
dguaraglia
-
-
-
Joined on 10-05-2007
-
Jaraguá do Sul, Brazil
-
Posts 36
-
-
|
Issue when binding custom column with DataGridView
Hi guys!
I'm using ES2008, Visual Studio 2005, MyGen 1.2.07, and MySQL.Data 5.1.2.2 (just to get that clear straight away :))
I have a query that returns a custom column I want to display in a DataGridView. The query looks is this:
Code:
Dim q As Data.ContractsQuery = Contracts.Query
q.es.JoinAlias = "Contracts"
Dim cq As New Data.ClientsQuery("Clients")
q.Select(cq.FirmName.As("ClientName"), q.Ends, q.Id, q.ReferenceNumber, q.RenewAutomatically)
q.Select(q.Finished)
q.InnerJoin(cq).On(cq.Id = q.ClientID)
q.Where(q.Ends < DateTime.Now.Date)
q.Where(q.Finished = False)
q.Load()
I'm using a BindingSource to link this to the table like this: Code:ContractsBindingSource.DataSource = Contracts.LowLevelBind()
ContractsBindingSource.ResetBindings(False) Now, I'm setting the column's "DataPropertyName" to "ClientName", and it works. Thing is: why do I need to bind to LowLevelBind? If I do ContractsBindingSource.DataSource = Contracts (if memory doesn't fail me, that's the way it works in ES2007), then the ClientName column appears empty in the DataGridView. Not a big issue, I know, but I think maybe some people might get confused without that key piece of information. I myself wrote a complete view because I couldn't find a work around this. (well, now I know, so I won't be doing it again :)) Cheers, David
|
|
-
07-01-2008, 6:22 AM |
-
Mike.Griffin
-
-
-
Joined on 01-14-2007
-
Indianapolis
-
Posts 3,059
-
-
|
Re: Issue when binding custom column with DataGridView
Try using the special "EntitySpaces.Core.dll" which can be found in the "C:\Program Files\EntitySpaces 2008\Runtimes\.NET 2.0\Web" folder. Link to this assembly and then bind directly to your entity/collection without using LowLevelBind() and let us know your results. You will need to browse specifically to this dll when adding your reference.
EntitySpaces | Twitter | BLOG | Please honor our Software License
|
|
-
07-01-2008, 6:45 AM |
-
dguaraglia
-
-
-
Joined on 10-05-2007
-
Jaraguá do Sul, Brazil
-
Posts 36
-
-
|
Re: Issue when binding custom column with DataGridView
Hmm, no luck with the \web binary. I tried using that assembly instead of the "regular" ES core one, but it's still not showing the values in the column. It works if I bind it to LowLevelBind. (BTW, I always had to browse to link to ES2008, probably it has to do with the fact I have ES2007 still laying around). There is a quite undesirable side-effect of using LowLevelBind I didn't know about. Namely, I'm not able to retrieve the original Data.Contracts object: Code:Dim contract as Data.Contracts = DirectCast(ContractsGrid.Rows(e.RowIndex).DataBoundItem, Data.Contracts) Because the row is bound to a DataRowView. It makes working with it a bit harder, but not impossible. If it gets more complicated than what I'm currently doing I might need to create a view for this particular case. I know I could go and build a custom property on the object, but I don't like having "dangling" properties that won't be holding values in every case. Why is the \web binary different? Cheers for the prompt response.
Cheers, David
|
|
-
07-01-2008, 8:25 AM |
-
Mike.Griffin
-
-
-
Joined on 01-14-2007
-
Indianapolis
-
Posts 3,059
-
-
|
Re: Issue when binding custom column with DataGridView
All of our testing shows that that binary fixes the issue you are having. I'm suprised it didn't work for you. However, it's very tricky to replace assemblies in ASP.NET projects as there are at least 2 secret places that microsoft runs your site out of.
C:\Documents and Settings\{username}\My Documents\Visual Studio 2005\Projects
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Of course those two paths might be different depending on the .NET version and VS version you are using. I really think that the fix will work for you.
EntitySpaces | Twitter | BLOG | Please honor our Software License
|
|
-
07-01-2008, 8:33 AM |
-
dguaraglia
-
-
-
Joined on 10-05-2007
-
Jaraguá do Sul, Brazil
-
Posts 36
-
-
|
Re: Issue when binding custom column with DataGridView
Well, mine is actually a WinForms project, but I guess you are right, there must be some cached version of the library somewhere, and as both binaries share the version number and name, .NET is probably just loading the cached version. I'll try to figure it out later if I can! Cheers, David
|
|
-
07-01-2008, 10:01 AM |
-
Mike.Griffin
-
-
-
Joined on 01-14-2007
-
Indianapolis
-
Posts 3,059
-
-
|
Re: Issue when binding custom column with DataGridView
Oh, that dll is only for ASP.NET. I will work up a windows forms app that tests this out for you.
EntitySpaces | Twitter | BLOG | Please honor our Software License
|
|
-
07-01-2008, 12:58 PM |
-
dguaraglia
-
-
-
Joined on 10-05-2007
-
Jaraguá do Sul, Brazil
-
Posts 36
-
-
|
Re: Issue when binding custom column with DataGridView
Yup, I guessed that was the ASP.NET version from the name of the directory, but still it worked quite well in WinForms (so, maybe that's also proof that .Net must be caching the assemblies. I don't even know if the ASP.NET version is supposed to work under winforms). I thank you for your keenness to solve the issue, but maybe this isn't working because of some project setting (for example, I enable "Option Strict On" on all my projects, although that wouldn't worry a C# programmer), or because of some particularity of the database/connector version. If you get something working, by all means send it, I'll try it here and try to work out what the difference migth be. Cheers, David
|
|
-
07-01-2008, 1:41 PM |
|
|
Re: Issue when binding custom column with DataGridView
I have VS set up so that VB projects have Option Explicit and Strict on by default, so that should not be an issue. I have not seen Join syntax like that, however. This works in my VB WinForm test app:
Code:Dim eq As New EmployeeQuery("e")
Dim cq As New CustomerQuery("c")
eq.Select(cq.CustomerName.As("ClientName"), eq.LastName, eq.FirstName)
eq.InnerJoin(cq).On(eq.EmployeeID = cq.Manager)
Dim collection As New EmployeeCollection()
collection.Load(eq)
BindingSource1.DataSource = collection
DataGridView1.DataSource = BindingSource1
David Neal Parsons www.entityspaces.net
|
|
-
07-01-2008, 2:18 PM |
-
dguaraglia
-
-
-
Joined on 10-05-2007
-
Jaraguá do Sul, Brazil
-
Posts 36
-
-
|
Re: Issue when binding custom column with DataGridView
Well, I discovered what the problem is all about. This code (adaptation of what you sent me) works flawlessly: Code:1 Dim q As New Data.ContractsQuery("Contracts")
2 Dim cq As New Data.ClientsQuery("Clients")
3 q.Select(cq.FirmName.As("ClientName"), q.Ends, q.Id, q.ReferenceNumber, q.RenewAutomatically)
4 q.Select(q.Finished)
5 q.InnerJoin(cq).On(cq.Id = q.ClientID)
6 q.Where(q.Ends < DateTime.Now.Date)
7 q.Where(q.Finished = False)
8
9 Dim c As New Data.ContractsCollection
10 c.Load(q)
11 ContractsBindingSource.DataSource = c
as you can see I'm creating the collection on line 9, whereas before I was using a collection I created using the WinForms designer. I normally do that, as I want to be able to see the property names at design time when I'm creating the columns, etc. So, to design the form I create an instance of a collection (Data.ContractsCollection), I then bind a BindingSource to that, and then bind the DataGridView to the BindingSource.
Now, why that? Surely there is an explanation? I'm really curious on why I can't use the same collection I designed by drag-dropping when I have a custom column, but it works OK when I don't. Mistery... Cheers, David
|
|
-
07-01-2008, 4:19 PM |
|
|
Re: Issue when binding custom column with DataGridView
This is a common mis-conception caused by the fact that the code generated in xxxx.Designer.vb is hidden away and should never be touched.
This is what you would see, and is all that is necessary for design-time support:
Code:Friend WithEvents EmployeeCollection1 As BusinessObjects.EmployeeCollection
At runtime, you can use the same collection, but you should always instantiate it before using it:
Code:Dim eq As New EmployeeQuery("e")
Dim cq As New CustomerQuery("c")
eq.Select(cq.CustomerName.As("ClientName"), eq.LastName, eq.FirstName)
eq.InnerJoin(cq).On(eq.EmployeeID = cq.Manager)
EmployeeCollection1 = New EmployeeCollection()
EmployeeCollection1.Load(eq)
BindingSource1.DataSource = EmployeeCollection1
David Neal Parsons www.entityspaces.net
|
|
-
07-02-2008, 1:08 AM |
-
dguaraglia
-
-
-
Joined on 10-05-2007
-
Jaraguá do Sul, Brazil
-
Posts 36
-
-
|
Re: Issue when binding custom column with DataGridView
Well, actually the designer *does* instantiate the collection in the InitializeComponent method, which is in turn called by the class constructor before anything else: Code:<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
...
Me.Contracts = New ContractManager.Data.ContractsCollection
and then:
Code:Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub Don't underestimate me, I'm just using VB.NET because it's a company policy so far and because, as John Leguizamo's character in Dawn Of The Dead says just before becoming a zombie, "I always wanted to look what the other side looks like" :P. Before I started working here I was using C# full time, and C++ before that, and C before that.
Besides, if the Contracts collection wasn't initialized somewhere, then I wouldn't be able to use it in my code without getting a runtime error. So, still there is something weird going on here, because when the collection gets instantiated by the designer, I don't get to see the column, but when I create it myself it shows the values. Maybe it has something to do with the default values the designer uses? Don't know, I'm just saying it would be interesting to know what's going on. Cheers, David
|
|
|
|
|