Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • I have 2 xtragrids. The first grid(Gridview1) is being populated using a standard dataset, doesn't contain many rows. What I would like to do is when the focused row of Gridview1 changes is populate the second xtragrid(Gridview2) using a linqinstantfeedbacksource based upon a cell value of Gridview1. The reason for using server mode on Gridview2 is because it will contain many rows. I am new to linq and am struggling with this. I have my data context setup using 2 tables (inventory_tbl and plants_tbl). They are linked to pull in the plantname based on the plantid stored in the inventory_tbl(simple join). Here is what I have so far:

                                    Public Class Inventoryfrm
                                        Private dbinventoryreceipts As New InventorySummaryDataContext
                                        Private startup As Boolean = True

                                        Private Sub Inventoryfrm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
                                            Me.Cursor = Cursors.WaitCursor
                                            Me.Get_Inventory_Summary_spTableAdapter.Fill(Me.InventorySummaryDSSP.Get_Inventory_Summary_sp)
                                            dbinventoryreceipts.ObjectTrackingEnabled = False
                                            Me.Cursor = Cursors.Default
                                        End Sub

                                        Private Sub GridView1_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridView1.FocusedRowChanged
                                            Dim x As Integer = GridView1.FocusedRowHandle
                                            If Me.GridView1.IsRowLoaded(x) = True Then
                                                InventoryInstantFeedbackSource1.KeyExpression = "ID"
                                                GridControl2.DataSource = InventoryInstantFeedbackSource1
                                            End If
                                        End Sub

                                        Private Sub InventoryInstantFeedbackSource1_DismissQueryable(sender As Object, e As DevExpress.Data.Linq.GetQueryableEventArgs) Handles InventoryInstantFeedbackSource1.DismissQueryable
                                            TryCast(e.Tag, InventorySummaryDataContext).Dispose()
                                        End Sub

                                        Private Sub InventoryInstantFeedbackSource1_GetQueryable(sender As Object, e As DevExpress.Data.Linq.GetQueryableEventArgs) Handles InventoryInstantFeedbackSource1.GetQueryable
                                            Dim selectedReceipts = From I In dbinventoryreceipts.Inventory_tbls _
                                                Join P In dbinventoryreceipts.Plants_tbls On P.ID Equals I.PlantID _
                                                Where I.IngredientID = Me.GridView1.GetFocusedRowCellValue("ID")
                                                Order By I.ReceiptDate Ascending _
                                                Select I.ID, I.ReceiptDate, I.ReceiptAmount, I.AmountRemaining, P.PlantName
                                            e.QueryableSource = selectedReceipts
                                            e.Tag = dbinventoryreceipts
                                        End Sub
                                    End Class

                                    My linq to sql query doesn't seem to be working for one. It is returning all the columns in the inventory_tbl, with no data, instead of just the ones I indicated in the query. Also how do I call the InventoryInstantFeedbackSource1_GetQueryable every time the focus is changed in Gridview1. Am I going about this the right way? What am I missing. Should I be approching this a different way.

                                    Thanks,
                                    Jad

                                Show all comments
                                • Hi Jad,

                                  Thank you for contacting us. I should say that I have little experience with Entity Framework and can't provide you with an answer as to why your query returns incorrect results. We aren't developers of Entity Framework. I suggest that you address this issue to Microsoft. I believe they can provide you with an appropriate solution.

                                  What about the question on how to update LinqInstantFeedbackSource on focused row changes: then it is necessary to create a new instance of LinqInstantFeedbackSource, subscribe it to the GetQueryable event, and assign it to the Grid.

                                  I hope this information will be helpful to you.

                                  Thanks,
                                  Gosha

                                • Jad Mayer 05.04.2012

                                  Could you provide a code sample of how to create a new instance of LinqInstantFeedbackSource, subscribe it to the GetQueryable event, and assign it to the Grid on when the row focus has changed?

                                  Thanks,
                                  Jad

                                • Hi Jad,

                                  I have created a sample project to demonstrate how to accomplish this task. Please let us know whether or not this solution meets your requirements. If it does not, feel free to reactivate this ticket.

                                  Thank you,
                                  Pavel.

                                • Jad Mayer 05.07.2012

                                  Thank You for the sample. This is close to what I am looking for. I have put together something similiar using the Northwind Database. This is attached. I populate the first gridview with Orders. What I would like is on focus change of the first gridview is query the Order Details table and display them in the second gridview, but with joining the products table, so that I can bring in the Product Name to display. I believe that this is a simple task, but am struggling with it. Can you take a look and see what I am missing? Also, on the example that you sent, I noticed you did not call the DismissQueryable. Is there no need to dispose of the dataContext?

                                  Thanks Again,
                                  Jad

                                • Hi Jad,

                                  Thank you for providing us with a sample project. I have updated it to demonstrate how to overcome this issue.

                                  Please feel free to reactivate this ticket if you need any further assistance with this issue.

                                  Thank you,
                                  Pavel.

                                • Jad Mayer 05.08.2012

                                  Thank You! This is exactly what I was looking for. Do I have to be concerned with disposing of anything in the DismissQueryable?

                                  Thanks,
                                  Jad

                                • Hi Jad,

                                  Yes, it is safer to handle the LinqInstantFeedbackSource.DismissQueryable event to dispose of the queryable source.

                                  I hope that you will find this information useful. Please feel free to reactivate this ticket if you need any further assistance with this issue.

                                  Thank you,
                                  Pavel.

                                • Jad Mayer 05.10.2012

                                  I have it working the way I want, but have some concerns. Maybe it is the way I am going about it, or things are not getting disposed of properly. I have implemented an xtrachart on the form also, and not sure if this is causing problems or not. I initial loading of the form everything is working fine, but after many clicks on gridview1(GridView1_FocusedRowChanged gets fired), I notice the system memory in the task manager continues to grow and the performance of filling gridview2 degrades terribly. Not sure if something is not geting disposed of properly or not. If I dispose of the datacontext in the _DismissQueryable, i get an error when I change focus. Can't call method on object that has been disposed of. Also if I hold down the "down arrow to invoke the gridview1_focusedrowchanged event, I will eventually get a Index out of range exception. I marked the line of code below indicating where this expeption is getting thrown. Here im code below. Can you see what I am missing or maybe I better way to implement this.

                                  Private querableSource As IQueryable
                                  Private dbinventoryreceipts As New InventorySummaryDataContext

                                  Private Sub Inventoryfrm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
                                          Me.Cursor = Cursors.WaitCursor
                                          Me.Get_Inventory_Summary_spTableAdapter.Fill(Me.InventorySummaryDSSP.Get_Inventory_Summary_sp)
                                          dbinventoryreceipts.ObjectTrackingEnabled = False
                                          InventoryInstantFeedbackSource1 = New DevExpress.Data.Linq.LinqInstantFeedbackSource()
                                          AddHandler InventoryInstantFeedbackSource1.GetQueryable, AddressOf InventoryInstantFeedbackSource1_GetQueryable
                                          AddHandler InventoryInstantFeedbackSource1.DismissQueryable, AddressOf InventoryInstantFeedbackSource1_DismissQueryable
                                          Me.Cursor = Cursors.Default
                                      End Sub

                                      Private Sub GridView1_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridView1.FocusedRowChanged
                                          Me.Cursor = Cursors.WaitCursor
                                          GridControl2.DataSource = Nothing
                                          GridView2.Columns.Clear()
                                          Dim ingid As Int32 = Convert.ToInt32(Me.GridView1.GetFocusedRowCellValue("ID"))
                                          querableSource = From inv In dbinventoryreceipts.Inventory_tbls _
                                                               Join plt In dbinventoryreceipts.Plants_tbls On plt.ID Equals inv.PlantID _
                                                               Join ing In dbinventoryreceipts.Ingredients_tbls On ing.ID Equals inv.IngredientID
                                                               Where inv.IngredientID = ingid _
                                                               Order By inv.ReceiptDate Ascending _
                                                               Select inv.ID, plt.PlantID, inv.PONumber, inv.ReceiptDate, inv.ReceiptAmount, inv.AmountRemaining, inv.ReceiptCostUnit, inv.BasePrice, inv.Active, inv.Reconciled
                                          InventoryInstantFeedbackSource1.KeyExpression = "ID"
                                          GridControl2.DataSource = InventoryInstantFeedbackSource1

                                  'this next line is where i get index out of range exception if i hold down the up or down button to invoke the gridview1_focusedrowchanged event

                                          GridView2.Columns(0).Caption = "Receipt ID"
                                          GridView2.Columns(0).Width = 50
                                          GridView2.Columns(1).GroupIndex = 1
                                          GridView2.Columns(2).Width = 60
                                          GridView2.Columns(3).DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
                                          GridView2.Columns(3).DisplayFormat.FormatString = "G"
                                          GridView2.Columns(6).Caption = "Cost/Unit"
                                          GridView2.Columns(8).Width = 50
                                          GridView2.Columns(9).Width = 65

                                          'Group Summaries
                                          Dim cnt As GridGroupSummaryItem = New GridGroupSummaryItem
                                          Dim inventory As GridGroupSummaryItem = New GridGroupSummaryItem
                                          Dim avgcost As GridGroupSummaryItem = New GridGroupSummaryItem
                                          Dim avgbase As GridGroupSummaryItem = New GridGroupSummaryItem
                                          'Count
                                          cnt.FieldName = "ID"
                                          cnt.SummaryType = DevExpress.Data.SummaryItemType.Count
                                          cnt.ShowInGroupColumnFooter = GridView2.Columns(3)
                                          cnt.DisplayFormat = "Count: {0}"
                                          GridView2.GroupSummary.Add(cnt)
                                          'Inventory
                                          inventory.FieldName = "AmountRemaining"
                                          inventory.SummaryType = DevExpress.Data.SummaryItemType.Sum
                                          inventory.ShowInGroupColumnFooter = GridView2.Columns(5)
                                          GridView2.GroupSummary.Add(inventory)
                                          'Avg Cost
                                          avgcost.FieldName = "ReceiptCostUnit"
                                          avgcost.SummaryType = DevExpress.Data.SummaryItemType.Average
                                          avgcost.ShowInGroupColumnFooter = GridView2.Columns(6)
                                          avgcost.DisplayFormat = "Avg: {0:c4}"
                                          GridView2.GroupSummary.Add(avgcost)
                                          'avg base
                                          avgbase.FieldName = "BasePrice"
                                          avgbase.SummaryType = DevExpress.Data.SummaryItemType.Average
                                          avgbase.DisplayFormat = "Avg: {0:c4}"
                                          avgbase.ShowInGroupColumnFooter = GridView2.Columns(7)
                                          GridView2.GroupSummary.Add(avgbase)
                                          cnt = Nothing
                                          inventory = Nothing
                                          avgbase = Nothing
                                          avgcost = Nothing

                                          'Grid Summaries
                                          GridView2.Columns(3).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count
                                          GridView2.Columns(3).SummaryItem.DisplayFormat = "Count: {0}"
                                          GridView2.Columns(5).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum
                                          GridView2.Columns(6).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average
                                          GridView2.Columns(6).SummaryItem.DisplayFormat = "Avg: {0:c4}"
                                          GridView2.Columns(7).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average
                                          GridView2.Columns(7).SummaryItem.DisplayFormat = "Avg: {0:c4}"
                                          'Filter
                                          Me.GridView2.ActiveFilterString = "[Active] = True And [Reconciled] = False"
                                          GridView2.Columns(3).SortOrder = DevExpress.Data.ColumnSortOrder.Ascending
                                          GridView2.ViewCaption = "Inventory Detail for " & GridView1.GetFocusedRowCellValue("Description")
                                          'chart usage
                                          If Me.GridView1.GetFocusedRowCellValue("ID") <> Nothing Then
                                              ChartControl1.Series.Clear()
                                              Dim cn1 As New SqlConnection(sqlconnectionstring)
                                              cn1.Open()
                                              Dim cmd1 As SqlCommand = New SqlCommand("Active_Plant_Lookup_sp", cn1)
                                              cmd1.CommandType = Data.CommandType.StoredProcedure
                                              Dim dr1 As SqlDataReader = cmd1.ExecuteReader
                                              Dim cn2 As New SqlConnection(sqlconnectionstring)
                                              cn2.Open()
                                              Do While dr1.Read()
                                                  Dim series1 As New Series("series1", ViewType.Line)
                                                  series1.Name = dr1.GetString(1)
                                                  Dim cmd2 As SqlCommand = New SqlCommand("Get_Plant_Usage_sp", cn2)
                                                  cmd2.CommandType = Data.CommandType.StoredProcedure
                                                  cmd2.Parameters.AddWithValue("@PlantID", dr1.GetValue(0))
                                                  cmd2.Parameters.AddWithValue("@IngredientID", Me.GridView1.GetFocusedRowCellValue("ID"))
                                                  cmd2.Parameters.AddWithValue("@Days", 14)
                                                  Dim dr2 As SqlDataReader = cmd2.ExecuteReader
                                                  Do While dr2.Read()
                                                      series1.Points.Add(New SeriesPoint(dr2.GetDateTime(0).ToShortDateString, dr2.GetValue(1)))
                                                  Loop
                                                  ChartControl1.Series.Add(series1)
                                                  dr2.Close()
                                                  dr2 = Nothing
                                                  cmd2.Dispose()
                                                  series1 = Nothing
                                              Loop
                                              dr1.Close()
                                              dr1 = Nothing
                                              cmd1.Dispose()
                                              cn1.Close()
                                              cn1.Dispose()
                                              cn2.Close()
                                              cn2.Dispose()
                                              ChartControl1.Titles(0).Text = "Inventory Usage for " & GridView1.GetFocusedRowCellValue("Description")
                                          Else
                                              ChartControl1.Series.Clear()
                                              ChartControl1.Titles(0).Text = ""
                                          End If
                                          Me.Cursor = Cursors.Default
                                  End Sub

                                  Private Sub InventoryInstantFeedbackSource1_GetQueryable(sender As Object, e As DevExpress.Data.Linq.GetQueryableEventArgs) Handles InventoryInstantFeedbackSource1.GetQueryable
                                          e.QueryableSource = querableSource
                                          e.Tag = dbinventoryreceipts
                                      End Sub

                                  For testing purposes I removed the code above that populates the Chartcontrol and am experiencing the same results, indicating my issue lies in the implementation of the linqinstandfeedbacksource.

                                  Thnaks,
                                  Jad

                                • Jad Mayer 05.14.2012

                                  Anything new on this. Still waiting for some input. Would it maybe be beter to query the whole table in and filter it based on the selection of the first grid? Not sure if this would be most efficient when this table will be millions of records long. Pleas advise

                                • We apologize for the late responce.

                                  I have not managed to reproduce this issue. Would you please provide us with a sample project that demonstrates the glitch, so that we can further investigate it and find a solution?

                                  I'm looking forward to your feedback.

                                • Jad Mayer 05.15.2012

                                  It occurs when I put in custom column properties and groupings. Run the app and highlight a row in gridview1, then hold down the "down" arrow and you will eventually get the error message I was talking about. Also pay attention to the memory usage in the task manager.

                                  Thanks,
                                  Jad

                                You must  log in  or  register  to leave comments

                                1 Solution

                                1

                                Thank you for pointing this out. I now see the issue. It is caused by the fact that you are customizing Grid columns, applying grouping and creating group summaries each time a focused row is changed. Please note that these operations are pretty resource-consuming. I suggest you perform all these customizations at design-time. After I have removed this code from the GridView.FocusedRowChanged event handler, the sample project operates very fast on my computer. Would you please test it in your environment and let us know of your results?

                                dxSample.zip
                                • Jad Mayer 05.18.2012

                                  Thank You! This seems to be the solution. I will continue to test and let you know if I run into any problems.

                                  Thanks,
                                  Jad

                                You must  log in  or  register  to leave comments

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners