Changing datagrid cell format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an editable datagrid in my app. I would like any changed text to be
bolded so that the user can easily review the changes before submitting them.
I don't see any event like 'onTextchange' or something that would allow me to
capture the cell that changed.
How can I bold the changed text before updating it?
Thanks!
 
Hi,

If you mean the WinForms datagrid, you will need a custom
DataGridColumnStyle. Take a look at the
System.Windows.Forms.DataGridColumnStyle MSDN docs, they should have an
example of creating a custom column style.

As a hint, you will most likely be able to inherit from
DataGridTextBoxColumn and to override PaintText to paint changed rows (which
can be detected by querying the corresponding DataViewRow's RowState (or was
it just State?) property).
 
Yes, I was talking about the datagrid, but my question is, what event is
triggered so that I know that a datarow has changed state? Is there an
onchangedstate event or something? Sorry if I am sounding dim, but I can
figure out how to change it (with formatting a columnstyle), but I don't know
what event would fire when the data changes.

Thanks,
Sara

Dmitriy Lapshin said:
Hi,

If you mean the WinForms datagrid, you will need a custom
DataGridColumnStyle. Take a look at the
System.Windows.Forms.DataGridColumnStyle MSDN docs, they should have an
example of creating a custom column style.

As a hint, you will most likely be able to inherit from
DataGridTextBoxColumn and to override PaintText to paint changed rows (which
can be detected by querying the corresponding DataViewRow's RowState (or was
it just State?) property).
 
Sara,

I'm afraid there's no explicit event. But, with my approach, you won't need
one. You will just have to check the row state whenever PaintText is called,
and if the state is 'changed' or 'updated', paint the text in bold. Believe
me, it *will* be called after the user finishes editing and commits the
changes.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Sara S said:
Yes, I was talking about the datagrid, but my question is, what event is
triggered so that I know that a datarow has changed state? Is there an
onchangedstate event or something? Sorry if I am sounding dim, but I can
figure out how to change it (with formatting a columnstyle), but I don't
know
what event would fire when the data changes.

Thanks,
Sara

Dmitriy Lapshin said:
Hi,

If you mean the WinForms datagrid, you will need a custom
DataGridColumnStyle. Take a look at the
System.Windows.Forms.DataGridColumnStyle MSDN docs, they should have an
example of creating a custom column style.

As a hint, you will most likely be able to inherit from
DataGridTextBoxColumn and to override PaintText to paint changed rows
(which
can be detected by querying the corresponding DataViewRow's RowState (or
was
it just State?) property).

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Sara S said:
I have an editable datagrid in my app. I would like any changed text to
be
bolded so that the user can easily review the changes before submitting
them.
I don't see any event like 'onTextchange' or something that would allow
me
to
capture the cell that changed.
How can I bold the changed text before updating it?
Thanks!
 
Dmitriy,
Thanks for your patience, but I am trying to bold the text before
committing, if the user has a lot of changes, they can be reviewed before
updating the database. Do you know of any event that I can use for that?
thanks,
Sara

Dmitriy Lapshin said:
Sara,

I'm afraid there's no explicit event. But, with my approach, you won't need
one. You will just have to check the row state whenever PaintText is called,
and if the state is 'changed' or 'updated', paint the text in bold. Believe
me, it *will* be called after the user finishes editing and commits the
changes.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Sara S said:
Yes, I was talking about the datagrid, but my question is, what event is
triggered so that I know that a datarow has changed state? Is there an
onchangedstate event or something? Sorry if I am sounding dim, but I can
figure out how to change it (with formatting a columnstyle), but I don't
know
what event would fire when the data changes.

Thanks,
Sara

Dmitriy Lapshin said:
Hi,

If you mean the WinForms datagrid, you will need a custom
DataGridColumnStyle. Take a look at the
System.Windows.Forms.DataGridColumnStyle MSDN docs, they should have an
example of creating a custom column style.

As a hint, you will most likely be able to inherit from
DataGridTextBoxColumn and to override PaintText to paint changed rows
(which
can be detected by querying the corresponding DataViewRow's RowState (or
was
it just State?) property).

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

I have an editable datagrid in my app. I would like any changed text to
be
bolded so that the user can easily review the changes before submitting
them.
I don't see any event like 'onTextchange' or something that would allow
me
to
capture the cell that changed.
How can I bold the changed text before updating it?
Thanks!
 
Sara,

The data are not immediately updated in the database upon the user
committing the changes in the grid. The changes are stored as the updated
versions of the altered data rows in the bound DataTable (or DataSet). The
changes are propagated to the database only when you call Update() on the
appropriate DataAdpater. So, my solution should do just what you want it to
do - after the user finishes editing data in a cell and goes to another
cell, the data in the changed cell are drawn in boldface. When, later, the
user clicks some sort of 'Save' button, all row versions are reset to
'Unchanged' by the DataAdapter, thus making all the cells to be rendered in
the regular font with.

Of course this won't work if you propagate the changes to the database as
soon as the user finishes editing the cell - in this scenario, the only
timeframe when the data are being changed and should be displayed in bold is
when the user is editing the cell contents. To this end, you should use the
TextBox property of the appropriate DataGridTextBoxColumn to properly
configure the Font property of the text box control hosted in a cell when
its data are being edited.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Sara S said:
Dmitriy,
Thanks for your patience, but I am trying to bold the text before
committing, if the user has a lot of changes, they can be reviewed before
updating the database. Do you know of any event that I can use for that?
thanks,
Sara

Dmitriy Lapshin said:
Sara,

I'm afraid there's no explicit event. But, with my approach, you won't
need
one. You will just have to check the row state whenever PaintText is
called,
and if the state is 'changed' or 'updated', paint the text in bold.
Believe
me, it *will* be called after the user finishes editing and commits the
changes.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Sara S said:
Yes, I was talking about the datagrid, but my question is, what event
is
triggered so that I know that a datarow has changed state? Is there an
onchangedstate event or something? Sorry if I am sounding dim, but I
can
figure out how to change it (with formatting a columnstyle), but I
don't
know
what event would fire when the data changes.

Thanks,
Sara

:

Hi,

If you mean the WinForms datagrid, you will need a custom
DataGridColumnStyle. Take a look at the
System.Windows.Forms.DataGridColumnStyle MSDN docs, they should have
an
example of creating a custom column style.

As a hint, you will most likely be able to inherit from
DataGridTextBoxColumn and to override PaintText to paint changed rows
(which
can be detected by querying the corresponding DataViewRow's RowState
(or
was
it just State?) property).

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

I have an editable datagrid in my app. I would like any changed text
to
be
bolded so that the user can easily review the changes before
submitting
them.
I don't see any event like 'onTextchange' or something that would
allow
me
to
capture the cell that changed.
How can I bold the changed text before updating it?
Thanks!
 
Back
Top