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.

Cheers

RE: BindingSource.Current is null on position change. by jp2msft

jp2msft
Mon Mar 17 08:59:03 CDT 2008

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.

"Gerard" wrote:

> 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.
>
> Cheers
>

Re: BindingSource.Current is null on position change. by RobinS

RobinS
Tue Mar 18 01:02:57 CDT 2008


"Gerard" <gerardlists@gmail.com> wrote in message
news:04ec197d-6a38-4277-8da6-8fdd2e52ea98@s19g2000prg.googlegroups.com...
> 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.
>
> Cheers

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


Re: BindingSource.Current is null on position change. by Gerard

Gerard
Tue Mar 18 04:01:14 CDT 2008

On Mar 18, 1:59=A0am, jp2msft <jp2m...@discussions.microsoft.com> wrote:
> Just an idea to get you started:
>
> if (tBLSitesBindingSource.Current !=3D null)
> {
> =A0 DataRowView view =3D (DataRowView)tBLSitesBindingSource.Current;
> =A0 // ...
>
> }
>
> 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.
>
>
>
> "Gerard" wrote:
> > Hi
> > I am trying to do a 1 to many relationship using dynamic textboxes,
> > binding navigator and a filter. =A0It 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:
>
> > =A0 =A0 =A0 =A0 =A0 =A0 DataRowView view =3D
> > (DataRowView)tBLSitesBindingSource.Current;
>
> > =A0// =A0crashes current =3D null;
> > =A0 =A0 =A0 =A0 =A0 =A0 string companyID =3D view.Row["companyID"].ToStr=
ing();
> > =A0// =A0crashes here after position change in bindingnav
>
> > =A0 =A0 =A0 =A0 =A0 =A0 tBLSitesBindingSource.Filter =3D "companyID =3D =
" + companyID;
>
> > =A0 =A0 =A0 =A0 =A0 =A0 for (int i =3D 0; i < rowCount; i++)
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TextBox tb =3D new TextBox();
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tb.DataBindings.Add(new
> > System.Windows.Forms.Binding("Text", tBLSitesBindingSource[i],
> > "siteName", true));
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 manyVertPos =3D manyVertPos + 40;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tb.Location =3D new System.Drawing.Point=
(5,
> > manyVertPos);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tb.Name =3D "ManyTxtBox" + i;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tb.Size =3D new System.Drawing.Size(178,=
20);
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 this.Controls.Add(tb);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GRPSites.Controls.Add(tb);
>
> > =A0 =A0 =A0 =A0 =A0 =A0 }
>
> > Is this an acceptible way of doing a 1 to many relationship or am I
> > barking up the wrong tree.
>
> > Cheers- Hide quoted text -
>
> - Show quoted text -

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.

cheers

Re: BindingSource.Current is null on position change. by Gerard

Gerard
Tue Mar 18 04:19:49 CDT 2008

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

cheers