Refresh only the CurrentRow of a DataGridView?  
Author Message
playmissy4me





PostPosted: Thu May 03 00:02:03 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? I have a DGV that is read only. When selecting a row, the item is edited in
individual controls elsewhere on the form, also bound to the same
bindingsource. The default behavior is that when the value is changed in a
textbox, it only repaints the value in the DGV cell after the textbox commits
the value to the underlying object. I want it to update the DGV cell's
display in real time. To do this, I have code in the textbox's TextChanged
event to update the underlying object's property and refresh the DGV. This
works ok. However, if there are more than a handful of records displayed,
this refresh is slow and distracting.

So two questions:
1) Am I approaching this the correct way? Is there a better way to have the
DGV reflect the changes in real time?
2)If this is the best way, is there any way to refresh/repaint only the
currently selected row?

Thanks for any ideas.

Barry

DotNet259  
 
 
RobinS





PostPosted: Thu May 03 00:02:03 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? Are you using a BindingSource? .Net 1.1 or .Net 2.0? C# or VB?

Robin S.
---------------------
"Barry Gilbert" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
>I have a DGV that is read only. When selecting a row, the item is edited
>in
> individual controls elsewhere on the form, also bound to the same
> bindingsource. The default behavior is that when the value is changed in
> a
> textbox, it only repaints the value in the DGV cell after the textbox
> commits
> the value to the underlying object. I want it to update the DGV cell's
> display in real time. To do this, I have code in the textbox's
> TextChanged
> event to update the underlying object's property and refresh the DGV.
> This
> works ok. However, if there are more than a handful of records displayed,
> this refresh is slow and distracting.
>
> So two questions:
> 1) Am I approaching this the correct way? Is there a better way to have
> the
> DGV reflect the changes in real time?
> 2)If this is the best way, is there any way to refresh/repaint only the
> currently selected row?
>
> Thanks for any ideas.
>
> Barry


 
 
BarryGilbert





PostPosted: Thu May 03 01:04:00 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? Bindingsource: Yes.
2.0
VB

Barry

"RobinS" wrote:

> Are you using a BindingSource? .Net 1.1 or .Net 2.0? C# or VB?
>
> Robin S.
> ---------------------
> "Barry Gilbert" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> >I have a DGV that is read only. When selecting a row, the item is edited
> >in
> > individual controls elsewhere on the form, also bound to the same
> > bindingsource. The default behavior is that when the value is changed in
> > a
> > textbox, it only repaints the value in the DGV cell after the textbox
> > commits
> > the value to the underlying object. I want it to update the DGV cell's
> > display in real time. To do this, I have code in the textbox's
> > TextChanged
> > event to update the underlying object's property and refresh the DGV.
> > This
> > works ok. However, if there are more than a handful of records displayed,
> > this refresh is slow and distracting.
> >
> > So two questions:
> > 1) Am I approaching this the correct way? Is there a better way to have
> > the
> > DGV reflect the changes in real time?
> > 2)If this is the best way, is there any way to refresh/repaint only the
> > currently selected row?
> >
> > Thanks for any ideas.
> >
> > Barry
>
>
>
 
 
RobinS





PostPosted: Sun May 06 23:29:59 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? I guess my question would be why are you doing this? It seems to me to make
more sense for the user to put in all the fields and then maybe hit a
<Save> button and it upgrades all the entries in that row at the same time.
Maybe he would like to see what the old values are before committing the
new ones?

If you are committed to this course of action, my question is when you say
this:

>> > it only repaints the value in the DGV cell after the textbox
>> > commits
>> > the value to the underlying object

what do you mean? Are you forcing an EndEdit() on the binding source, or a
Validate() or do you mean actually updating the data source?

Seems to me you might be able to accomplish this by databinding the same
data source to the same binding source. So you have a table that is data
bound to your DGV, and then you bind the textbox to the same data source
with the same binding source. I think it will show the same information?
Have you tried that?

Are you using data tables/datasets or business objects? If you are using
business objects, you can implement INotifyPropertyChanged and it will
repaint the grid automatically.

Robin S.
---------------------

"Barry Gilbert" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Bindingsource: Yes.
> 2.0
> VB
>
> Barry
>
> "RobinS" wrote:
>
>> Are you using a BindingSource? .Net 1.1 or .Net 2.0? C# or VB?
>>
>> Robin S.
>> ---------------------
>> "Barry Gilbert" <EMail@HideDomain.com> wrote in
>> message
>> news:EMail@HideDomain.com...
>> >I have a DGV that is read only. When selecting a row, the item is
>> >edited
>> >in
>> > individual controls elsewhere on the form, also bound to the same
>> > bindingsource. The default behavior is that when the value is changed
>> > in
>> > a
>> > textbox, it only repaints the value in the DGV cell after the textbox
>> > commits
>> > the value to the underlying object. I want it to update the DGV cell's
>> > display in real time. To do this, I have code in the textbox's
>> > TextChanged
>> > event to update the underlying object's property and refresh the DGV.
>> > This
>> > works ok. However, if there are more than a handful of records
>> > displayed,
>> > this refresh is slow and distracting.
>> >
>> > So two questions:
>> > 1) Am I approaching this the correct way? Is there a better way to
>> > have
>> > the
>> > DGV reflect the changes in real time?
>> > 2)If this is the best way, is there any way to refresh/repaint only
>> > the
>> > currently selected row?
>> >
>> > Thanks for any ideas.
>> >
>> > Barry
>>
>>
>>


 
 
BarryGilbert





PostPosted: Mon May 07 08:43:01 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? Robin,
Thanks for your reply.

"RobinS" wrote:

> I guess my question would be why are you doing this? It seems to me to make
> more sense for the user to put in all the fields and then maybe hit a
> <Save> button and it upgrades all the entries in that row at the same time.
> Maybe he would like to see what the old values are before committing the
> new ones?

I want the user to see the results of their changes in the dgv in real time.
This is why I want this behavior. If I don't do this, the behavior can be
confusing. Besides textboxes, I also have checkboxes. If the default behavior
is retained, it isn't obvious to the user that they have successfully changed
the checkbox's value until the leave the control. The next control they need
to click might be the Save button, but there are some validation rules which
disable the save button. In this case, it seems clumsy to ask the user to tab
off every control to see his changes, especially if they only want to click
Save.

> If you are committed to this course of action, my question is when you say
> this:
>
> >> > it only repaints the value in the DGV cell after the textbox
> >> > commits
> >> > the value to the underlying object
>
> what do you mean? Are you forcing an EndEdit() on the binding source, or a
> Validate() or do you mean actually updating the data source?

When I say this is the default behavior, I mean that it's how the
BindingSource/dgv work without any intervention on my part. I already have
both the dgv and the individual textboxes bound to the same bindingSource.
When you do this, the dgv only reflects changes to the bndingSource, which is
only updated when the textbox's value is committed, by exiting the control.

> Seems to me you might be able to accomplish this by databinding the same
> data source to the same binding source. So you have a table that is data
> bound to your DGV, and then you bind the textbox to the same data source
> with the same binding source. I think it will show the same information?
> Have you tried that?
>
> Are you using data tables/datasets or business objects? If you are using
> business objects, you can implement INotifyPropertyChanged and it will
> repaint the grid automatically.
>
I am binding to custom business objects which do implement
INotifyPropertyChanged. However, as I've mentioned, while it does repaint the
grid automatically, it does so only after the property in the bindingsource
is updated, which occurs only after the textbox's value is committed, when
leaving the control.

Barry
 
 
BarryGilbert





PostPosted: Mon May 07 08:45:01 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? Robin,
Thanks for your reply.

"RobinS" wrote:

> I guess my question would be why are you doing this? It seems to me to make
> more sense for the user to put in all the fields and then maybe hit a
> <Save> button and it upgrades all the entries in that row at the same time.
> Maybe he would like to see what the old values are before committing the
> new ones?

I want the user to see the results of their changes in the dgv in real time.
This is why I want this behavior. If I don't do this, the behavior can be
confusing. Besides textboxes, I also have checkboxes. If the default behavior
is retained, it isn't obvious to the user that they have successfully changed
the checkbox's value until the leave the control. The next control they need
to click might be the Save button, but there are some validation rules which
disable the save button. In this case, it seems clumsy to ask the user to tab
off every control to see his changes, especially if they only want to click
Save.

> If you are committed to this course of action, my question is when you say
> this:
>
> >> > it only repaints the value in the DGV cell after the textbox
> >> > commits
> >> > the value to the underlying object
>
> what do you mean? Are you forcing an EndEdit() on the binding source, or a
> Validate() or do you mean actually updating the data source?

When I say this is the default behavior, I mean that it's how the
BindingSource/dgv work without any intervention on my part. I already have
both the dgv and the individual textboxes bound to the same bindingSource.
When you do this, the dgv only reflects changes to the bndingSource, which is
only updated when the textbox's value is committed, by exiting the control.

> Seems to me you might be able to accomplish this by databinding the same
> data source to the same binding source. So you have a table that is data
> bound to your DGV, and then you bind the textbox to the same data source
> with the same binding source. I think it will show the same information?
> Have you tried that?
>
> Are you using data tables/datasets or business objects? If you are using
> business objects, you can implement INotifyPropertyChanged and it will
> repaint the grid automatically.
>
I am binding to custom business objects which do implement
INotifyPropertyChanged. However, as I've mentioned, while it does repaint the
grid automatically, it does so only after the property in the bindingsource
is updated, which occurs only after the textbox's value is committed, when
leaving the control.

Barry
 
 
Brian





PostPosted: Mon May 07 10:47:32 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? Is there a reason you're using a read-only DataGridView instead of an
editable grid, which would save all this synchronization trouble?

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets

"Barry Gilbert" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Robin,
> Thanks for your reply.
>
> "RobinS" wrote:
>
>> I guess my question would be why are you doing this? It seems to me to
>> make
>> more sense for the user to put in all the fields and then maybe hit a
>> <Save> button and it upgrades all the entries in that row at the same
>> time.
>> Maybe he would like to see what the old values are before committing the
>> new ones?
>
> I want the user to see the results of their changes in the dgv in real
> time.
> This is why I want this behavior. If I don't do this, the behavior can be
> confusing. Besides textboxes, I also have checkboxes. If the default
> behavior
> is retained, it isn't obvious to the user that they have successfully
> changed
> the checkbox's value until the leave the control. The next control they
> need
> to click might be the Save button, but there are some validation rules
> which
> disable the save button. In this case, it seems clumsy to ask the user to
> tab
> off every control to see his changes, especially if they only want to
> click
> Save.
>
>> If you are committed to this course of action, my question is when you
>> say
>> this:
>>
>> >> > it only repaints the value in the DGV cell after the textbox
>> >> > commits
>> >> > the value to the underlying object
>>
>> what do you mean? Are you forcing an EndEdit() on the binding source, or
>> a
>> Validate() or do you mean actually updating the data source?
>
> When I say this is the default behavior, I mean that it's how the
> BindingSource/dgv work without any intervention on my part. I already have
> both the dgv and the individual textboxes bound to the same bindingSource.
> When you do this, the dgv only reflects changes to the bndingSource, which
> is
> only updated when the textbox's value is committed, by exiting the
> control.
>
>> Seems to me you might be able to accomplish this by databinding the same
>> data source to the same binding source. So you have a table that is data
>> bound to your DGV, and then you bind the textbox to the same data source
>> with the same binding source. I think it will show the same information?
>> Have you tried that?
>>
>> Are you using data tables/datasets or business objects? If you are using
>> business objects, you can implement INotifyPropertyChanged and it will
>> repaint the grid automatically.
>>
> I am binding to custom business objects which do implement
> INotifyPropertyChanged. However, as I've mentioned, while it does repaint
> the
> grid automatically, it does so only after the property in the
> bindingsource
> is updated, which occurs only after the textbox's value is committed, when
> leaving the control.
>
> Barry


 
 
BarryGilbert





PostPosted: Mon May 07 11:00:00 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? Brian,

I beat my head against the wall for three weeks trying to use in-line
editing in the dgv. There were too many issues, especially with combobox
columns. In my humble opinion, the dgv is still a disappointing
work-in-process. Using seperate editing controls ended up being a better,
more intuitive solution.

Barry

"Brian Schwartz" wrote:

> Is there a reason you're using a read-only DataGridView instead of an
> editable grid, which would save all this synchronization trouble?
>
> --
> Brian Schwartz
> FishNet Components
> http://www.fishnetcomponents.com
> Fish Grid .NET Light: Powerful Layouts for Small Datasets
>
> "Barry Gilbert" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > Robin,
> > Thanks for your reply.
> >
> > "RobinS" wrote:
> >
> >> I guess my question would be why are you doing this? It seems to me to
> >> make
> >> more sense for the user to put in all the fields and then maybe hit a
> >> <Save> button and it upgrades all the entries in that row at the same
> >> time.
> >> Maybe he would like to see what the old values are before committing the
> >> new ones?
> >
> > I want the user to see the results of their changes in the dgv in real
> > time.
> > This is why I want this behavior. If I don't do this, the behavior can be
> > confusing. Besides textboxes, I also have checkboxes. If the default
> > behavior
> > is retained, it isn't obvious to the user that they have successfully
> > changed
> > the checkbox's value until the leave the control. The next control they
> > need
> > to click might be the Save button, but there are some validation rules
> > which
> > disable the save button. In this case, it seems clumsy to ask the user to
> > tab
> > off every control to see his changes, especially if they only want to
> > click
> > Save.
> >
> >> If you are committed to this course of action, my question is when you
> >> say
> >> this:
> >>
> >> >> > it only repaints the value in the DGV cell after the textbox
> >> >> > commits
> >> >> > the value to the underlying object
> >>
> >> what do you mean? Are you forcing an EndEdit() on the binding source, or
> >> a
> >> Validate() or do you mean actually updating the data source?
> >
> > When I say this is the default behavior, I mean that it's how the
> > BindingSource/dgv work without any intervention on my part. I already have
> > both the dgv and the individual textboxes bound to the same bindingSource.
> > When you do this, the dgv only reflects changes to the bndingSource, which
> > is
> > only updated when the textbox's value is committed, by exiting the
> > control.
> >
> >> Seems to me you might be able to accomplish this by databinding the same
> >> data source to the same binding source. So you have a table that is data
> >> bound to your DGV, and then you bind the textbox to the same data source
> >> with the same binding source. I think it will show the same information?
> >> Have you tried that?
> >>
> >> Are you using data tables/datasets or business objects? If you are using
> >> business objects, you can implement INotifyPropertyChanged and it will
> >> repaint the grid automatically.
> >>
> > I am binding to custom business objects which do implement
> > INotifyPropertyChanged. However, as I've mentioned, while it does repaint
> > the
> > grid automatically, it does so only after the property in the
> > bindingsource
> > is updated, which occurs only after the textbox's value is committed, when
> > leaving the control.
> >
> > Barry
>
>
>
 
 
BarryGilbert





PostPosted: Tue May 08 14:40:01 CDT 2007 Top

Winforms >> Refresh only the CurrentRow of a DataGridView? For posterity, I've figured out how to do this:

myDataGridView.InvalidateRow(myDataGridView.CurrentRow.Index)

Barry

"Barry Gilbert" wrote:

> I have a DGV that is read only. When selecting a row, the item is edited in
> individual controls elsewhere on the form, also bound to the same
> bindingsource. The default behavior is that when the value is changed in a
> textbox, it only repaints the value in the DGV cell after the textbox commits
> the value to the underlying object. I want it to update the DGV cell's
> display in real time. To do this, I have code in the textbox's TextChanged
> event to update the underlying object's property and refresh the DGV. This
> works ok. However, if there are more than a handful of records displayed,
> this refresh is slow and distracting.
>
> So two questions:
> 1) Am I approaching this the correct way? Is there a better way to have the
> DGV reflect the changes in real time?
> 2)If this is the best way, is there any way to refresh/repaint only the
> currently selected row?
>
> Thanks for any ideas.
>
> Barry