Groups | Blog | Home
all groups > dotnet ado.net > march 2008 >

dotnet ado.net : BindingSource.Current is null on position change.



Gerard
3/15/2008 3:25:30 PM
Hi
I am trying to do a 1 to many relationship using dynamic textboxes,
binding navigator and a filter. It works on form_load but when i
change to the next row on the bindingNavigator I get.

"Object reference not set to an instance of an object."

Here is the code:

DataRowView view =
(DataRowView)tBLSitesBindingSource.Current;


// crashes current = null;
string companyID = view.Row["companyID"].ToString();
// crashes here after position change in bindingnav


tBLSitesBindingSource.Filter = "companyID = " + companyID;

for (int i = 0; i < rowCount; i++)
{
TextBox tb = new TextBox();
tb.DataBindings.Add(new
System.Windows.Forms.Binding("Text", tBLSitesBindingSource[i],
"siteName", true));
manyVertPos = manyVertPos + 40;
tb.Location = new System.Drawing.Point(5,
manyVertPos);
tb.Name = "ManyTxtBox" + i;
tb.Size = new System.Drawing.Size(178, 20);

this.Controls.Add(tb);
GRPSites.Controls.Add(tb);

}

Is this an acceptible way of doing a 1 to many relationship or am I
barking up the wrong tree.

jp2msft
3/17/2008 6:59:03 AM
Just an idea to get you started:

if (tBLSitesBindingSource.Current != null)
{
DataRowView view = (DataRowView)tBLSitesBindingSource.Current;
// ...
}

I can't tell you anything about the 1 to many relationship part, though. I'm
not that good at databases at this point and time.

[quoted text, click to view]
RobinS
3/17/2008 11:02:57 PM

[quoted text, click to view]

Ok, I'll bite. What exactly are you trying to do? Why don't you show the
results of the filtering in a DataGridView? Do you re-create all of the
textboxes every time the user changes records?

RobinS.
GoldMail.com
Gerard
3/18/2008 2:01:14 AM
[quoted text, click to view]

I ve tried something similar the problem was that it always returns
null even though I know there are records there. It doesn't break out
of loop.

Gerard
3/18/2008 2:19:49 AM
To be honest I just don't like how the data grid looks. Saying that
if there are more then 20 rows, I will redirect to something
different. What I'm trying to do is say for 1 company I may have 3
sites a1 a2 a3. So if on the binding navigator I move poistion to
site a, then only sites a1, a2 and a3 show as text boxes, along with a
delete and save buttons. The filtering was to select only a1,a2, a3
without getting b1 b2 c3 etc

AddThis Social Bookmark Button