Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi there i got another problem :(

 

let me explain i have a search form with some text boxes and a datagrid. ok if i type some string into one textbox and then press F2 it searches in the databes for the string and then commit the result back and i load the results into the datagrid so far so good :)

 

if i click on a grid row it first clears the databindings from all textboxes and then binds the textboxes again to the data (most of em are text databindings) then i can click around the grid and get the actual data to the textboxes BUT if i bind the Tag property of a textbox to some data like an ID and then click around i get an error like this

 

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

 

and then the program halts at the class definition of the main form :( (Public class form2)

 

how can i fix this?

 

i also noticed that if i bind data to the text property of a textbox and if i type this textbox1.databindings.add("text",datasource,"ID") then this error occurs too if i change text to Text the error wont occur

Posted

Examine the line of code in which the error occurs. One of the variables there is supposed to point to an object, but the object has not been instantiated so far.

 

(That's the typical reason behind the NullReferenceException)

.nerd
Posted

hehe i know the line of code its the line where i bind the tag property from a textbox to data

 

as long as i bind the text property to data it all works fine i can navigate in the grid up and down this error occurs only if i bind a tag property to any of the textboxes :confused:

 

ok heres the working example

 

            stlaenge.DataBindings.Clear()
           stlaenge.DataBindings.Add("Text", datasource, "StammTeilLaenge")
           stdim.DataBindings.Clear()
           stdim.DataBindings.Add("Text", datasource, "StammDimension")
           stwst.DataBindings.Clear()
           stwst.DataBindings.Add("Text", datasource, "StammWerkstoff")

 

and here is the not working example

 

            stlaenge.DataBindings.Clear()
           stlaenge.DataBindings.Add("Tag", datasource, "StammTeilLaenge")
           stdim.DataBindings.Clear()
           stdim.DataBindings.Add("Text", datasource, "StammDimension")
           stwst.DataBindings.Clear()
           stwst.DataBindings.Add("Text", datasource, "StammWerkstoff")

Posted (edited)
And you are sure the Tag property is not nothing ?

 

no, the value of the data is 1, anyways i can bind the text property to the same data and all works, the error occurs only when i bind the tag property of the text box

 

i forgot, i can bind the tag property the error occours then only if i navigate trough the grid up and down, so the tag properties changes every time

Edited by soniix

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...