vaioklm Posted February 13, 2008 Report Share Posted February 13, 2008 I create a lookup field using the following code: Dim luSysNo As GridFX.WebForms.LookupFieldluSysNo = New GridFX.WebForms.LookupFieldluSysNo.DataPath = "cll_sys_no"luSysNo.ReadOnly = FalseluSysNo.MissingValueText = "Missing"Dim liItem As New GridFX.WebForms.LookupItemliItem.Text = "Test"liItem.Value = "0"luSysNo.LookupItems.Add(liItem)DataFields.Add(CType(luSysNo, GridFX.WebForms.DataField))Dim fcSysNo As GridFX.WebForms.FieldColumnfcSysNo = New GridFX.WebForms.FieldColumn(CType(luSysNo, GridFX.WebForms.DataField))fcSysNo.Title = ""fcSysNo.Visible = TruefcSysNo.Style.Wrap = FalseColumns.Add(fcSysNo) The grid renders fine and I see my "Test" and "Missing" values as I would expect. But as soon as I put it into edit mode, I get the following error: There was a problem while processing your request. The specific error message was: Exception type: System.NullReferenceExceptionMessage: Object reference not set to an instance of an object.Stack Trace: at GridFX.WebForms.LookupField.n() at GridFX.WebForms.LookupField.p() at GridFX.WebForms.LookupField.q() at GridFX.WebForms.LookupField.a(ListItemCollection A_0, LookupFieldInputSettings A_1) at GridFX.WebForms.LookupField.a(IFieldControl A_0, Object A_1) at GridFX.WebForms.DataField.i(IFieldControl A_0) at dc.b() at l3.k() at System.Web.UI.Control.EnsureChildControls() at l3.c(EventArgs A_0) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.AddedControl(Control control, Int32 index) at System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) at GridFX.WebForms.OutputCellContainer.b.a(Int32 A_0, OutputCell A_1) at GridFX.WebForms.OutputCellContainer.a(Object A_0, ListChangeEventArgs`1 A_1) at GridFX.WebForms.GridItem.a(Object A_0, ListChangeEventArgs`1 A_1) at GridFX.WebForms.ObservableList`1.a(ListChangeEventArgs`1 A_0) at GridFX.WebForms.ObservableList`1.Add(T item) at is.d() at GridFX.WebForms.GridItem.t() at GridFX.WebForms.GridItem.set_Editing(Boolean value) at GridFX.WebForms.GridCommands.g(CellContainerCommandArgs`1 A_0) at GridFX.WebForms.Command`1.b(TArgs A_0) at GridFX.WebForms.Command`1.a(CommandArgs A_0) at GridFX.WebForms.Grid.a(String A_0, pb A_1) at GridFX.WebForms.Grid.i(String A_0) If I remove the lookup field, the grid will go into edit mode without error. Quote Link to comment Share on other sites More sharing options...
AngelR Posted February 18, 2008 Report Share Posted February 18, 2008 What event are you using when creating the Lookup Field? Quote Link to comment Share on other sites More sharing options...
vaioklm Posted February 18, 2008 Author Report Share Posted February 18, 2008 The DataBinding Event. That is where I am adding all of my columns to the Grid. Quote Link to comment Share on other sites More sharing options...
AngelR Posted February 18, 2008 Report Share Posted February 18, 2008 Hi, sorry about the delay in getting a response. The exception you got could be a limitation in Grid.Databinding event. We add a new event (Grid.DataSourceSelecting) that will be available in the next Service Pack, to be available soon. This new event (DataSourceSelecting) overcomes some limitations we were having in the Grid_Databind event, most of them when connecting the grid programmatically. From now on when you use Grid FX Smart Tag Wizard to choose a datasource to connect the grid you'll see a new option: In Code and once you select it, an Event Handler will be created and a grid property will be set to true: DataSourceInCode. To try this, there is a recent Hotfix that you can download to test. You will receive a personalized message with download instructions. Here is a sample using BrokerageCompany and Agents tables I used to populate a Lookup field dynamically in the Grid.DataSourceSelecting Event. Protected Sub Grid1_DataSourceSelecting(ByVal sender As Object, ByVal e As GridFX.WebForms.DataSourceSelectingEventArgs) Handles Grid1.DataSourceSelecting 'Let's populate the grid using Agents Datasource Grid1.DataSource = Data_BusinessObject.GetAgents() 'Let's fill a different datasource with Brokerage CompaniesDim BrokersDv As New System.Data.DataView BrokersDv = Data_BusinessObject.GetBrokers() 'Casting the brokerage_id field as the LookupField to be filledDim LookupField As New GridFX.WebForms.LookupField LookupField = Grid1.DataFields("brokerage_id") 'for every datarow in Brokerage_Company table we add an Item to brokerage_id LookupField 'Brokerage_name will be looked up to replace brokerage_id valueFor Each row As Data.DataRow In BrokersDv.Table.Rows Dim LookupFieldItem As New GridFX.WebForms.LookupItemLookupFieldItem.Text = row.Item("brokerage_name")LookupFieldItem.Value = row.Item("brokerage_id") LookupField.LookupItems.Add(LookupFieldItem) Next End Sub Let me know if this helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.