I have a checkbox, date time picker & few comboboxes bound to the same
dataset

I know checkbox, datetimepicker won't let me have null when I call AddNew()

Also because if I bind my combo boxes to the same dataset they all change
automagically.

So my theory:

On Addnew(), before addnew is called, unbind the checkbox & datetimepicker &
comboboxes and before endcommit is called, populate the new record with the
value in these controls.

sounds good eh ? Now can someone help me put that into code?

Thanks :)

HS

Re: Addnew() by Keenan

Keenan
Thu Feb 17 00:10:43 CST 2005

why can't you default the values of the checkbox contolr and the
datetimepicker control


Re: Addnew() by news

news
Thu Feb 17 03:37:29 CST 2005

Checkbox I can

Date is not always possible like "hire date" or "date of birth" the client
wants it blank rather than giving it some vague date as default.

Also then the issue remains with multiple combo boxes bound to the same
datasource.

Thanks

"Keenan Newton" <kameleon_dj@yahoo.com> wrote in message
news:1108620643.316683.40030@f14g2000cwb.googlegroups.com...
> why can't you default the values of the checkbox contolr and the
> datetimepicker control
>



Re: Addnew() by Keenan

Keenan
Thu Feb 17 08:51:47 CST 2005

Well with the datetimepicker is setting a DateTime value, Since
DateTime cannot be null, a date must be there. As for the multiple
cobo boxes what i tyoically do i once I get my busienss entity (dataset
or whatever) I add a record to it and call it "<Please Specify>" or
maybe "<Non Selected>". If you need to have a blank datetimepicker try
looking for some third party controls (infragistics, Component One,
etc...)


RE: Addnew() by BonnieBerentCMVP

BonnieBerentCMVP
Thu Feb 17 23:39:02 CST 2005

DateTime stuff is really tricky for some reason. We had to write a lot of
code in our DateTimeControl subclass to handle stuff. I didn't write the
code, so I can't point you in the right direction, other than to say that it
needs a lot of work.

Now, the issue with the multiple Combos ... you need to have different
Tables as your DataSource for each Combo. It's simple enough to do though ...
just make a Copy of each table and use a copy for each Combo's DataSource.

~~Bonnie

"Hemang Shah" wrote:

> I have a checkbox, date time picker & few comboboxes bound to the same
> dataset
>
> I know checkbox, datetimepicker won't let me have null when I call AddNew()
>
> Also because if I bind my combo boxes to the same dataset they all change
> automagically.
>
> So my theory:
>
> On Addnew(), before addnew is called, unbind the checkbox & datetimepicker &
> comboboxes and before endcommit is called, populate the new record with the
> value in these controls.
>
> sounds good eh ? Now can someone help me put that into code?
>
> Thanks :)
>
> HS
>
>
>

Re: Addnew() by Hemang

Hemang
Fri Feb 18 12:31:10 CST 2005

I understand its tricky

But what if I don't want to bind it ?

Before calling ADDNew() I unbind the checkbox and datetime

Before calling endcurrentEdit I assign the value of these controls to my
binding.current.[fields] = datetimepicker.value

and then called update. Won't that work ?

I'm not able to get my typed dataset to give me false for null boolean for
checkboxes either.

Thanks

Hemang
"Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
in message news:F67AEF30-C7E2-4744-87A8-9B022E4BFC6A@microsoft.com...
> DateTime stuff is really tricky for some reason. We had to write a lot of
> code in our DateTimeControl subclass to handle stuff. I didn't write the
> code, so I can't point you in the right direction, other than to say that
> it
> needs a lot of work.
>
> Now, the issue with the multiple Combos ... you need to have different
> Tables as your DataSource for each Combo. It's simple enough to do though
> ...
> just make a Copy of each table and use a copy for each Combo's DataSource.
>
> ~~Bonnie
>
> "Hemang Shah" wrote:
>
>> I have a checkbox, date time picker & few comboboxes bound to the same
>> dataset
>>
>> I know checkbox, datetimepicker won't let me have null when I call
>> AddNew()
>>
>> Also because if I bind my combo boxes to the same dataset they all change
>> automagically.
>>
>> So my theory:
>>
>> On Addnew(), before addnew is called, unbind the checkbox &
>> datetimepicker &
>> comboboxes and before endcommit is called, populate the new record with
>> the
>> value in these controls.
>>
>> sounds good eh ? Now can someone help me put that into code?
>>
>> Thanks :)
>>
>> HS
>>
>>
>>



Re: Addnew() by BonnieBerentCMVP

BonnieBerentCMVP
Fri Feb 18 15:05:03 CST 2005

I assume that you're using the DataBinding's AddNew() method? I doubt if that
will work correctly if you're unbinding your controls. I don't add rows that
way ... instead I add directly to the DataTable, so you'd do something like
this:

DataRow row = MyTable.NewRow();
// code to populate the row
MyTable.Rows.Add(row);

Although, it seems kinda kludgy to handle it this way (by unbinding stuff).
I think it's better to take the time to write a DateTime picker sub-class.

Also, for the CheckBox DBNULL problem ... that's easily handled by a
sub-class of the CheckBox control by having an Event Handler for the Format
event:

protected virtual void FormatHandler(object sender, ConvertEventArgs e)
{
if (e.Value == System.DBNull.Value)
e.Value = false;
}

~~Bonnie



"Hemang Shah" wrote:

> I understand its tricky
>
> But what if I don't want to bind it ?
>
> Before calling ADDNew() I unbind the checkbox and datetime
>
> Before calling endcurrentEdit I assign the value of these controls to my
> binding.current.[fields] = datetimepicker.value
>
> and then called update. Won't that work ?
>
> I'm not able to get my typed dataset to give me false for null boolean for
> checkboxes either.
>
> Thanks
>
> Hemang
> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
> in message news:F67AEF30-C7E2-4744-87A8-9B022E4BFC6A@microsoft.com...
> > DateTime stuff is really tricky for some reason. We had to write a lot of
> > code in our DateTimeControl subclass to handle stuff. I didn't write the
> > code, so I can't point you in the right direction, other than to say that
> > it
> > needs a lot of work.
> >
> > Now, the issue with the multiple Combos ... you need to have different
> > Tables as your DataSource for each Combo. It's simple enough to do though
> > ...
> > just make a Copy of each table and use a copy for each Combo's DataSource.
> >
> > ~~Bonnie
> >
> > "Hemang Shah" wrote:
> >
> >> I have a checkbox, date time picker & few comboboxes bound to the same
> >> dataset
> >>
> >> I know checkbox, datetimepicker won't let me have null when I call
> >> AddNew()
> >>
> >> Also because if I bind my combo boxes to the same dataset they all change
> >> automagically.
> >>
> >> So my theory:
> >>
> >> On Addnew(), before addnew is called, unbind the checkbox &
> >> datetimepicker &
> >> comboboxes and before endcommit is called, populate the new record with
> >> the
> >> value in these controls.
> >>
> >> sounds good eh ? Now can someone help me put that into code?
> >>
> >> Thanks :)
> >>
> >> HS
> >>
> >>
> >>
>
>
>

Re: Addnew() by Hemang

Hemang
Fri Feb 18 16:59:46 CST 2005

Thanks Bonnie

I don't mind taking the time to write subclass for null for datetimepicker,
I just don't know how. Codeproject has a good control but according to the
messages on it, its not fully operational. I can't even find a commercial
control that I can pay for.

I'll google subclass to see how do I do that.

I know about the format & parse method. But don't I have to do that for
each checkbox on my form ?

I guess not, if there is a way to format the base checkbox control from
where everyone is instanced from. I have to do this in a separate dll ? or
I can do it in my app itself.

I'm migrating from Access development as I wanted to take the plunge into
"real" development, these are rough waters though.

If you can point me to any article on this it would be great.

Thanks a lot again

HS

"Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
in message news:42DAF71B-EBAA-4ACC-902B-FC6B1258D40B@microsoft.com...
>I assume that you're using the DataBinding's AddNew() method? I doubt if
>that
> will work correctly if you're unbinding your controls. I don't add rows
> that
> way ... instead I add directly to the DataTable, so you'd do something
> like
> this:
>
> DataRow row = MyTable.NewRow();
> // code to populate the row
> MyTable.Rows.Add(row);
>
> Although, it seems kinda kludgy to handle it this way (by unbinding
> stuff).
> I think it's better to take the time to write a DateTime picker sub-class.
>
> Also, for the CheckBox DBNULL problem ... that's easily handled by a
> sub-class of the CheckBox control by having an Event Handler for the
> Format
> event:
>
> protected virtual void FormatHandler(object sender, ConvertEventArgs e)
> {
> if (e.Value == System.DBNull.Value)
> e.Value = false;
> }
>
> ~~Bonnie
>
>
>
> "Hemang Shah" wrote:
>
>> I understand its tricky
>>
>> But what if I don't want to bind it ?
>>
>> Before calling ADDNew() I unbind the checkbox and datetime
>>
>> Before calling endcurrentEdit I assign the value of these controls to my
>> binding.current.[fields] = datetimepicker.value
>>
>> and then called update. Won't that work ?
>>
>> I'm not able to get my typed dataset to give me false for null boolean
>> for
>> checkboxes either.
>>
>> Thanks
>>
>> Hemang
>> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com>
>> wrote
>> in message news:F67AEF30-C7E2-4744-87A8-9B022E4BFC6A@microsoft.com...
>> > DateTime stuff is really tricky for some reason. We had to write a lot
>> > of
>> > code in our DateTimeControl subclass to handle stuff. I didn't write
>> > the
>> > code, so I can't point you in the right direction, other than to say
>> > that
>> > it
>> > needs a lot of work.
>> >
>> > Now, the issue with the multiple Combos ... you need to have different
>> > Tables as your DataSource for each Combo. It's simple enough to do
>> > though
>> > ...
>> > just make a Copy of each table and use a copy for each Combo's
>> > DataSource.
>> >
>> > ~~Bonnie
>> >
>> > "Hemang Shah" wrote:
>> >
>> >> I have a checkbox, date time picker & few comboboxes bound to the same
>> >> dataset
>> >>
>> >> I know checkbox, datetimepicker won't let me have null when I call
>> >> AddNew()
>> >>
>> >> Also because if I bind my combo boxes to the same dataset they all
>> >> change
>> >> automagically.
>> >>
>> >> So my theory:
>> >>
>> >> On Addnew(), before addnew is called, unbind the checkbox &
>> >> datetimepicker &
>> >> comboboxes and before endcommit is called, populate the new record
>> >> with
>> >> the
>> >> value in these controls.
>> >>
>> >> sounds good eh ? Now can someone help me put that into code?
>> >>
>> >> Thanks :)
>> >>
>> >> HS
>> >>
>> >>
>> >>
>>
>>
>>



Re: Addnew() by BonnieBerentCMVP

BonnieBerentCMVP
Fri Feb 18 17:37:03 CST 2005

Let me give you a little Jump Start on sub-classes. Sub-classing the base
controls is the first thing one should do in any language. I've been doing it
for years ... way before I ever started with .NET. There are always little
quirks in behavior in some of the base class controls that you want to get
around for every instance of an object.

Say, as an example, that you've developed a few forms for your application.
You've used the base class controls. At some point, you find something's not
quite acting right and you want to change that behavior or you may just want
to add something (some properties or something) to every ComboBox that you
use. Now, since you used the base class controls to begin with ... guess
what? You're outta luck!! You've got a lot of work ahead of you to change all
those. Whereas, if you had sub-classed all the controls first (even if you
haven't as yet put code in those sub-classes) and used the sub-classed
controls on your forms, then you'll have no extra work to do when you make
changes to your sub-classed control. (and yes, even the form should be
sub-classed).


Basically, you'll want a class library that contains your sub-classed UI
controls, like textbox, button, checkbox, etc. Something like this:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MyCompany.WinUI.MyClasses
{
public class MyComboBox : System.Windows.Forms.ComboBox
{
// code here
}

public class MyTextBox : System.Windows.Forms.TextBox
{
// code here
}

public class MyButton : System.Windows.Forms.Button
{
// code here
}
}

That's it. These controls can't be sub-classed visually, but as you can see,
it's easy enough to do it in code. I have all the basic controls sub-classed
in one class library file. Once they're added to the ToolBox, then can be
dragged onto any design surface in the IDE.

And this is what I was talking about when I said to put a Format
eventhandler in your CheckBox ... put it in the sub-class and then you'll
never have to worry about it again.

I hope this helps you get started!!

~~Bonnie


"Hemang Shah" wrote:

> Thanks Bonnie
>
> I don't mind taking the time to write subclass for null for datetimepicker,
> I just don't know how. Codeproject has a good control but according to the
> messages on it, its not fully operational. I can't even find a commercial
> control that I can pay for.
>
> I'll google subclass to see how do I do that.
>
> I know about the format & parse method. But don't I have to do that for
> each checkbox on my form ?
>
> I guess not, if there is a way to format the base checkbox control from
> where everyone is instanced from. I have to do this in a separate dll ? or
> I can do it in my app itself.
>
> I'm migrating from Access development as I wanted to take the plunge into
> "real" development, these are rough waters though.
>
> If you can point me to any article on this it would be great.
>
> Thanks a lot again
>
> HS
>

Re: Addnew() by Hemang

Hemang
Mon Feb 21 08:22:40 CST 2005

Hello

I tried this, but when i call AddNew() the form is not refreshed with blank
items. As soon as I unbind to this check box it blanks out:

using System;

using System.Windows.Forms;

using System.ComponentModel;

using System.Drawing;

namespace ctlNullCheckBox

{

/// <summary>

/// Summary description for ctlChkBox.

/// </summary>

public class ctlChkBox : System.Windows.Forms.CheckBox

{

protected virtual void FormatHandler(object sender,
System.Windows.Forms.ConvertEventArgs e)

{

if (e.Value == System.DBNull.Value)

e.Value = false;

}

public ctlChkBox()

{

//

// TODO: Add constructor logic here

//

}

}

}



Am I missing something ?

Thanks



"Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
in message news:42DAF71B-EBAA-4ACC-902B-FC6B1258D40B@microsoft.com...
>I assume that you're using the DataBinding's AddNew() method? I doubt if
>that
> will work correctly if you're unbinding your controls. I don't add rows
> that
> way ... instead I add directly to the DataTable, so you'd do something
> like
> this:
>
> DataRow row = MyTable.NewRow();
> // code to populate the row
> MyTable.Rows.Add(row);
>
> Although, it seems kinda kludgy to handle it this way (by unbinding
> stuff).
> I think it's better to take the time to write a DateTime picker sub-class.
>
> Also, for the CheckBox DBNULL problem ... that's easily handled by a
> sub-class of the CheckBox control by having an Event Handler for the
> Format
> event:
>
> protected virtual void FormatHandler(object sender, ConvertEventArgs e)
> {
> if (e.Value == System.DBNull.Value)
> e.Value = false;
> }
>
> ~~Bonnie
>
>
>
> "Hemang Shah" wrote:
>
>> I understand its tricky
>>
>> But what if I don't want to bind it ?
>>
>> Before calling ADDNew() I unbind the checkbox and datetime
>>
>> Before calling endcurrentEdit I assign the value of these controls to my
>> binding.current.[fields] = datetimepicker.value
>>
>> and then called update. Won't that work ?
>>
>> I'm not able to get my typed dataset to give me false for null boolean
>> for
>> checkboxes either.
>>
>> Thanks
>>
>> Hemang
>> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com>
>> wrote
>> in message news:F67AEF30-C7E2-4744-87A8-9B022E4BFC6A@microsoft.com...
>> > DateTime stuff is really tricky for some reason. We had to write a lot
>> > of
>> > code in our DateTimeControl subclass to handle stuff. I didn't write
>> > the
>> > code, so I can't point you in the right direction, other than to say
>> > that
>> > it
>> > needs a lot of work.
>> >
>> > Now, the issue with the multiple Combos ... you need to have different
>> > Tables as your DataSource for each Combo. It's simple enough to do
>> > though
>> > ...
>> > just make a Copy of each table and use a copy for each Combo's
>> > DataSource.
>> >
>> > ~~Bonnie
>> >
>> > "Hemang Shah" wrote:
>> >
>> >> I have a checkbox, date time picker & few comboboxes bound to the same
>> >> dataset
>> >>
>> >> I know checkbox, datetimepicker won't let me have null when I call
>> >> AddNew()
>> >>
>> >> Also because if I bind my combo boxes to the same dataset they all
>> >> change
>> >> automagically.
>> >>
>> >> So my theory:
>> >>
>> >> On Addnew(), before addnew is called, unbind the checkbox &
>> >> datetimepicker &
>> >> comboboxes and before endcommit is called, populate the new record
>> >> with
>> >> the
>> >> value in these controls.
>> >>
>> >> sounds good eh ? Now can someone help me put that into code?
>> >>
>> >> Thanks :)
>> >>
>> >> HS
>> >>
>> >>
>> >>
>>
>>
>>



Re: Addnew() by BonnieBerentCMVP

BonnieBerentCMVP
Mon Feb 21 14:51:04 CST 2005

OK, first of all, don't create your CheckBox sub-class this way. Use the
example I posted earlier as the way to do it.

Second, you're missing the delegate for the FormatHandler(). The Format
event is actually an event on the Binding, so somewhere in your sub-class you
should have method for adding a binding and then set the delegate to the
Format event there. Something like this (just to get you started):

Binding oBinding;
DataTable BoundTable;
string BoundColumn;

public virtual void DataBind(DataTable dt, string column)
{
this.Checked = false;
this.oBinding = new Binding("Checked", dt, column);
this.oBinding.Format += new ConvertEventHandler(this.FormatHandler);
}

~~Bonnie



"Hemang Shah" wrote:

> Hello
>
> I tried this, but when i call AddNew() the form is not refreshed with blank
> items. As soon as I unbind to this check box it blanks out:
>
> using System;
>
> using System.Windows.Forms;
>
> using System.ComponentModel;
>
> using System.Drawing;
>
> namespace ctlNullCheckBox
>
> {
>
> /// <summary>
>
> /// Summary description for ctlChkBox.
>
> /// </summary>
>
> public class ctlChkBox : System.Windows.Forms.CheckBox
>
> {
>
> protected virtual void FormatHandler(object sender,
> System.Windows.Forms.ConvertEventArgs e)
>
> {
>
> if (e.Value == System.DBNull.Value)
>
> e.Value = false;
>
> }
>
> public ctlChkBox()
>
> {
>
> //
>
> // TODO: Add constructor logic here
>
> //
>
> }
>
> }
>
> }
>
>
>
> Am I missing something ?
>
> Thanks
>
>
>
> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
> in message news:42DAF71B-EBAA-4ACC-902B-FC6B1258D40B@microsoft.com...
> >I assume that you're using the DataBinding's AddNew() method? I doubt if
> >that
> > will work correctly if you're unbinding your controls. I don't add rows
> > that
> > way ... instead I add directly to the DataTable, so you'd do something
> > like
> > this:
> >
> > DataRow row = MyTable.NewRow();
> > // code to populate the row
> > MyTable.Rows.Add(row);
> >
> > Although, it seems kinda kludgy to handle it this way (by unbinding
> > stuff).
> > I think it's better to take the time to write a DateTime picker sub-class.
> >
> > Also, for the CheckBox DBNULL problem ... that's easily handled by a
> > sub-class of the CheckBox control by having an Event Handler for the
> > Format
> > event:
> >
> > protected virtual void FormatHandler(object sender, ConvertEventArgs e)
> > {
> > if (e.Value == System.DBNull.Value)
> > e.Value = false;
> > }
> >
> > ~~Bonnie
>

Re: Addnew() by Hemang

Hemang
Tue Feb 22 14:54:48 CST 2005

I gave up :(

I used :

this.BindingContext[dvClient].EndCurrentEdit();
this.BindingContext[dvClient].SuspendBinding();
this.BindingContext[dvClient].AddNew();
DataRowView drv = (DataRowView) this.BindingContext[dvClient].Current;
drv["ChildMinding"] = false; // these are the boolean checkboxes
drv["WorkPermit"] = false; // these are the boolean checkboxes
drv["WorkCDN"] = false; // these are the boolean checkboxes
this.BindingContext[dvClient].ResumeBinding();
this.BindingContext[dvClient].Position =
this.BindingContext[dvClient].Count -1;

and I bound the dates to the text field and that seems to work! why have
value & text then?
I know this is not the best method, but i'm past my deadline for the
project. But thanks so much for this immense help. Not many people take
this kind of efforts to teach.
I tried to mail you but it bounced back (Yeah I checked the proxy email
later lol).
Cheers.
HS

"Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
in message news:9D9DEB39-10F3-4CF8-810A-C3CAFA1E7595@microsoft.com...
> OK, first of all, don't create your CheckBox sub-class this way. Use the
> example I posted earlier as the way to do it.
>
> Second, you're missing the delegate for the FormatHandler(). The Format
> event is actually an event on the Binding, so somewhere in your sub-class
> you
> should have method for adding a binding and then set the delegate to the
> Format event there. Something like this (just to get you started):
>
> Binding oBinding;
> DataTable BoundTable;
> string BoundColumn;
>
> public virtual void DataBind(DataTable dt, string column)
> {
> this.Checked = false;
> this.oBinding = new Binding("Checked", dt, column);
> this.oBinding.Format += new ConvertEventHandler(this.FormatHandler);
> }
>
> ~~Bonnie
>
>
>
> "Hemang Shah" wrote:
>
>> Hello
>>
>> I tried this, but when i call AddNew() the form is not refreshed with
>> blank
>> items. As soon as I unbind to this check box it blanks out:
>>
>> using System;
>>
>> using System.Windows.Forms;
>>
>> using System.ComponentModel;
>>
>> using System.Drawing;
>>
>> namespace ctlNullCheckBox
>>
>> {
>>
>> /// <summary>
>>
>> /// Summary description for ctlChkBox.
>>
>> /// </summary>
>>
>> public class ctlChkBox : System.Windows.Forms.CheckBox
>>
>> {
>>
>> protected virtual void FormatHandler(object sender,
>> System.Windows.Forms.ConvertEventArgs e)
>>
>> {
>>
>> if (e.Value == System.DBNull.Value)
>>
>> e.Value = false;
>>
>> }
>>
>> public ctlChkBox()
>>
>> {
>>
>> //
>>
>> // TODO: Add constructor logic here
>>
>> //
>>
>> }
>>
>> }
>>
>> }
>>
>>
>>
>> Am I missing something ?
>>
>> Thanks
>>
>>
>>
>> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com>
>> wrote
>> in message news:42DAF71B-EBAA-4ACC-902B-FC6B1258D40B@microsoft.com...
>> >I assume that you're using the DataBinding's AddNew() method? I doubt if
>> >that
>> > will work correctly if you're unbinding your controls. I don't add rows
>> > that
>> > way ... instead I add directly to the DataTable, so you'd do something
>> > like
>> > this:
>> >
>> > DataRow row = MyTable.NewRow();
>> > // code to populate the row
>> > MyTable.Rows.Add(row);
>> >
>> > Although, it seems kinda kludgy to handle it this way (by unbinding
>> > stuff).
>> > I think it's better to take the time to write a DateTime picker
>> > sub-class.
>> >
>> > Also, for the CheckBox DBNULL problem ... that's easily handled by a
>> > sub-class of the CheckBox control by having an Event Handler for the
>> > Format
>> > event:
>> >
>> > protected virtual void FormatHandler(object sender, ConvertEventArgs e)
>> > {
>> > if (e.Value == System.DBNull.Value)
>> > e.Value = false;
>> > }
>> >
>> > ~~Bonnie
>>



Re: Addnew() by BonnieBerentCMVP

BonnieBerentCMVP
Tue Feb 22 15:19:04 CST 2005

Sorry that you had to give up, but I realize how those darn deadlines can
creep up on you. When you have more time though, you should try messing
around with the concepts that I showed you, as far as sub-classing your
controls and, in particular, the code for the CheckBox. It would make your
next project far more easier.

Good luck!

~~Bonnie


"Hemang Shah" wrote:

> I gave up :(
>
> I used :
>
> this.BindingContext[dvClient].EndCurrentEdit();
> this.BindingContext[dvClient].SuspendBinding();
> this.BindingContext[dvClient].AddNew();
> DataRowView drv = (DataRowView) this.BindingContext[dvClient].Current;
> drv["ChildMinding"] = false; // these are the boolean checkboxes
> drv["WorkPermit"] = false; // these are the boolean checkboxes
> drv["WorkCDN"] = false; // these are the boolean checkboxes
> this.BindingContext[dvClient].ResumeBinding();
> this.BindingContext[dvClient].Position =
> this.BindingContext[dvClient].Count -1;
>
> and I bound the dates to the text field and that seems to work! why have
> value & text then?
> I know this is not the best method, but i'm past my deadline for the
> project. But thanks so much for this immense help. Not many people take
> this kind of efforts to teach.
> I tried to mail you but it bounced back (Yeah I checked the proxy email
> later lol).
> Cheers.
> HS
>
> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com> wrote
> in message news:9D9DEB39-10F3-4CF8-810A-C3CAFA1E7595@microsoft.com...
> > OK, first of all, don't create your CheckBox sub-class this way. Use the
> > example I posted earlier as the way to do it.
> >
> > Second, you're missing the delegate for the FormatHandler(). The Format
> > event is actually an event on the Binding, so somewhere in your sub-class
> > you
> > should have method for adding a binding and then set the delegate to the
> > Format event there. Something like this (just to get you started):
> >
> > Binding oBinding;
> > DataTable BoundTable;
> > string BoundColumn;
> >
> > public virtual void DataBind(DataTable dt, string column)
> > {
> > this.Checked = false;
> > this.oBinding = new Binding("Checked", dt, column);
> > this.oBinding.Format += new ConvertEventHandler(this.FormatHandler);
> > }
> >
> > ~~Bonnie
> >
> >
> >
> > "Hemang Shah" wrote:
> >
> >> Hello
> >>
> >> I tried this, but when i call AddNew() the form is not refreshed with
> >> blank
> >> items. As soon as I unbind to this check box it blanks out:
> >>
> >> using System;
> >>
> >> using System.Windows.Forms;
> >>
> >> using System.ComponentModel;
> >>
> >> using System.Drawing;
> >>
> >> namespace ctlNullCheckBox
> >>
> >> {
> >>
> >> /// <summary>
> >>
> >> /// Summary description for ctlChkBox.
> >>
> >> /// </summary>
> >>
> >> public class ctlChkBox : System.Windows.Forms.CheckBox
> >>
> >> {
> >>
> >> protected virtual void FormatHandler(object sender,
> >> System.Windows.Forms.ConvertEventArgs e)
> >>
> >> {
> >>
> >> if (e.Value == System.DBNull.Value)
> >>
> >> e.Value = false;
> >>
> >> }
> >>
> >> public ctlChkBox()
> >>
> >> {
> >>
> >> //
> >>
> >> // TODO: Add constructor logic here
> >>
> >> //
> >>
> >> }
> >>
> >> }
> >>
> >> }
> >>
> >>
> >>
> >> Am I missing something ?
> >>
> >> Thanks
> >>
> >>
> >>
> >> "Bonnie Berent [C# MVP]" <BonnieBerentCMVP@discussions.microsoft.com>
> >> wrote
> >> in message news:42DAF71B-EBAA-4ACC-902B-FC6B1258D40B@microsoft.com...
> >> >I assume that you're using the DataBinding's AddNew() method? I doubt if
> >> >that
> >> > will work correctly if you're unbinding your controls. I don't add rows
> >> > that
> >> > way ... instead I add directly to the DataTable, so you'd do something
> >> > like
> >> > this:
> >> >
> >> > DataRow row = MyTable.NewRow();
> >> > // code to populate the row
> >> > MyTable.Rows.Add(row);
> >> >
> >> > Although, it seems kinda kludgy to handle it this way (by unbinding
> >> > stuff).
> >> > I think it's better to take the time to write a DateTime picker
> >> > sub-class.
> >> >
> >> > Also, for the CheckBox DBNULL problem ... that's easily handled by a
> >> > sub-class of the CheckBox control by having an Event Handler for the
> >> > Format
> >> > event:
> >> >
> >> > protected virtual void FormatHandler(object sender, ConvertEventArgs e)
> >> > {
> >> > if (e.Value == System.DBNull.Value)
> >> > e.Value = false;
> >> > }
> >> >
> >> > ~~Bonnie
> >>
>
>
>