PC Review


Reply
Thread Tools Rate Thread

DataGridView: Displaying empty cells for certain values

 
 
Ashutosh
Guest
Posts: n/a
 
      30th Oct 2008
Hi,
I have a DataGridView which has as typed data-set associated with it.
For the table which I am displaying in it, I want to display certain
cells (corresponding to a column in the database) to be displayed as
blank instead of the value 0 (Zero - integer). Also, I want the value 0
(zero) to be saved to the database when the changes are applied/saved
and if the cells are blank.

I tried to change the text that is drawn/shown in the grid by handling
the CellPainting event, but the Value and FormattedValue properties are
read only.

How can I achieve this?

Thanks & Regards,
Ashutosh
 
Reply With Quote
 
 
 
 
Matthias Krug
Guest
Posts: n/a
 
      30th Oct 2008
Ashutosh schrieb:
> Hi,
> I have a DataGridView which has as typed data-set associated with it.
> For the table which I am displaying in it, I want to display certain
> cells (corresponding to a column in the database) to be displayed as
> blank instead of the value 0 (Zero - integer). Also, I want the value 0
> (zero) to be saved to the database when the changes are applied/saved
> and if the cells are blank.
>
> I tried to change the text that is drawn/shown in the grid by handling
> the CellPainting event, but the Value and FormattedValue properties are
> read only.
>
> How can I achieve this?


How about a quick and dirty one?
Use the CellPainting to make ForeColor=BackColor for those Cells with a
zero in them
 
Reply With Quote
 
Zhi-Xin Ye [MSFT]
Guest
Posts: n/a
 
      31st Oct 2008
Hi Ashutosh,

You can handle the CellFormatting event instead. For example:

void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0 && e.Value != null)
{
if ((int)e.Value == 0)
{
e.Value = "";
}
}
}


For more information about the CellFormatting event , you can refer to this
document:

CellFormatting event
http://msdn.microsoft.com/en-us/libr...atagridview.ce
llformatting.aspx

Please try my suggestion, and let me know the result.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can

improve the support we provide to you. Please feel free to let my manager
know what you think of the level

of service provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the

community or a Microsoft Support Engineer within 2 business day is
acceptable. Please note that each follow

up response may take approximately 2 business days as the support
professional working with you may need

further investigation to reach the most efficient resolution. The offering
is not appropriate for situations

that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working

with a dedicated Microsoft Support Engineer by contacting Microsoft
Customer Support Services (CSS) at

http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


 
Reply With Quote
 
Ashutosh
Guest
Posts: n/a
 
      31st Oct 2008
Hi Matthias,

Actually that was the first solution that came to my mind. But the
problem with that approach is that the value of zero will still be there
and user can select/copy it. Thanks anyways

Thanks & Regards,
Ashutosh

Matthias Krug wrote:
> Ashutosh schrieb:
>> Hi,
>> I have a DataGridView which has as typed data-set associated with it.
>> For the table which I am displaying in it, I want to display certain
>> cells (corresponding to a column in the database) to be displayed as
>> blank instead of the value 0 (Zero - integer). Also, I want the value
>> 0 (zero) to be saved to the database when the changes are
>> applied/saved and if the cells are blank.
>>
>> I tried to change the text that is drawn/shown in the grid by
>> handling the CellPainting event, but the Value and FormattedValue
>> properties are read only.
>>
>> How can I achieve this?

>
> How about a quick and dirty one?
> Use the CellPainting to make ForeColor=BackColor for those Cells with
> a zero in them

 
Reply With Quote
 
Ashutosh
Guest
Posts: n/a
 
      31st Oct 2008
Hi Zhi,
Thanks for the information. I need little more help here.

For these columns, if the user doesn't enter any value (while editing or
adding a record), a value of NULL is added to the database. How can
override this so that I update the database with value of Zero and still
display an empty cell in the grid.

Thanks & Regards,
Ashutosh

Zhi-Xin Ye [MSFT] wrote:
> Hi Ashutosh,
>
> You can handle the CellFormatting event instead. For example:
>
> void dataGridView1_CellFormatting(object sender,
> DataGridViewCellFormattingEventArgs e)
> {
> if (e.ColumnIndex == 0 && e.Value != null)
> {
> if ((int)e.Value == 0)
> {
> e.Value = "";
> }
> }
> }
>
>
> For more information about the CellFormatting event , you can refer to this
> document:
>
> CellFormatting event
> http://msdn.microsoft.com/en-us/libr...atagridview.ce
> llformatting.aspx
>
> Please try my suggestion, and let me know the result.
>
> Sincerely,
> Zhi-Xin Ye
> Microsoft Managed Newsgroup Support Team
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can
>
> improve the support we provide to you. Please feel free to let my manager
> know what you think of the level
>
> of service provided. You can send feedback directly to my manager at:
> (E-Mail Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
>
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the
>
> community or a Microsoft Support Engineer within 2 business day is
> acceptable. Please note that each follow
>
> up response may take approximately 2 business days as the support
> professional working with you may need
>
> further investigation to reach the most efficient resolution. The offering
> is not appropriate for situations
>
> that require urgent, real-time or phone-based interactions. Issues of this
> nature are best handled working
>
> with a dedicated Microsoft Support Engineer by contacting Microsoft
> Customer Support Services (CSS) at
>
> http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>

 
Reply With Quote
 
Zhi-Xin Ye [MSFT]
Guest
Posts: n/a
 
      31st Oct 2008
Hi Ashutosh,

You can handle the CellParsing event.

DataGridView.CellParsing event
http://msdn.microsoft.com/en-us/libr...atagridview.ce
llparsing.aspx

If you have any questions or concerns, please don't hesitate to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can

improve the support we provide to you. Please feel free to let my manager
know what you think of the level

of service provided. You can send feedback directly to my manager at:
(E-Mail Removed).

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
clearing values of cells in named range(s) so the cells are empty BRC Microsoft Excel Programming 1 10th Jan 2010 06:54 AM
skip cells with zero values in chart (cells not empty) =?Utf-8?B?amhhbGxAaWZveA==?= Microsoft Excel Charting 3 2nd Jun 2009 02:11 PM
Get rid of empty cells when displaying Data validation list mbeauchamp Microsoft Excel Misc 6 5th Oct 2006 09:37 PM
Displaying empty cells as zero in report FA Microsoft Access Queries 2 8th Sep 2005 07:05 AM
Please help! Displaying only rows with empty cells in a numeric field using Advanced Filter. Thanks =?Utf-8?B?Sk9DQQ==?= Microsoft Excel New Users 1 5th Jun 2004 02:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:47 AM.