473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to determine if fontstyle is bold or regular in a datagridview

I have code to bold text in a datagridviewcell:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim cs As DataGridViewCellStyle, fnt As Font
For Each c As DataGridViewCell In dgrv1.SelectedCells
cs = c.Style
Console.WriteLine(c.Style.Font)
fnt = dgrv1.Font
Console.WriteLine(fnt.Name)
cs.Font = New Font(fnt.Name, fnt.Size, FontStyle.Bold)
Next
End Sub

This works fine for bolding the text in the datagridviewcell, but how to
unbold this text?

I want to be able to click the same button to unbold the text in selected
cells in the datagridview if the text is bold. But if the text is not bold
then make the text bold. Like a toggle. I can only set fnt to the
datagridview.Font property. I tried setting fnt to the
datagridviewcell.style.font property but that did not set anything to fnt.

I tried the following to determine if Fontstyle was regular but it errored out

Dim cs As DataGridViewCellStyle, fnt As Font
For Each c As DataGridViewCell In dgrv1.SelectedCells
cs = c.Style
fnt = dgrv1.Font
If cs.Font.Style = FontStyle.Regular Then '--error here
cs.Font = New Font(fnt.Name, fnt.Size, FontStyle.Bold)
End If
Next

The error message for the following line of code

If cs.Font.Style = FontStyle.Regular

said that the object was not set - referring to the Font object -

but this was the only syntax that contained FontStyle expression in the
intellisense. Anybody have an idea how to determine if the fontstyle,
bold/regular, for a datagridviewcell?

Thanks,
Rich

Mar 21 '07 #1
2 7719
Instead of

If cs.Font.Style = FontStyle.Regular Then '--error here
cs.Font = New Font(fnt.Name, fnt.Size,
FontStyle.Bold)
End If

you might try this code:

If cs.Font is Nothing OrElse cs.Font.Style =
FontStyle.Regular Then
cs.Font = New Font(fnt.Name, fnt.Size,
FontStyle.Bold)
End If
================
Clay Burch
Synfusion, Inc.

Mar 21 '07 #2
Rocknroll ! that did the trick! Thanks (JIT because I just got tasked with
something way less fun)

Thanks again

"ClayB" wrote:
Instead of

If cs.Font.Style = FontStyle.Regular Then '--error here
cs.Font = New Font(fnt.Name, fnt.Size,
FontStyle.Bold)
End If

you might try this code:

If cs.Font is Nothing OrElse cs.Font.Style =
FontStyle.Regular Then
cs.Font = New Font(fnt.Name, fnt.Size,
FontStyle.Bold)
End If
================
Clay Burch
Synfusion, Inc.

Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Victor Martin | last post by:
Bold text in proportional fonts use up more space than non-bold text. Is there a way to keep the space bold takes up within the limits of the regular text while keeping the same font?
1
by: OutdoorGuy | last post by:
Greetings, I am attempting to use the code below to print information on a Windows form. The code itself is working fine, but I simply want to change the font of the label to be both Bold and...
0
by: osmarjunior | last post by:
I'm using a DataGridView in Windows Forms. I made an intelligent search tool that searches in multiple fields, of multiple tables in my database. What I wanna do is make just a part of a cell...
2
by: andreas | last post by:
When I select a text in a richtextbox to set de selected text in bold, regular, italic .. or non I want to do that with one click Thus I must find out if the selected text is already in bold,...
2
by: Tiago Salgado | last post by:
I everyone... i'm having some problems when i'm trying to change a item fontstyle in a listview (details view). Code: frmMain.FeedsList.Items(CInt(id1)).Font.Style = FontStyle.Regular The...
2
by: genojoe | last post by:
Is it possible to include one line of bold text followed by one line of regular text in the MsgBox control? What I would like to see is the following lines <Bold>The text you entered isn't an...
1
by: Roger | last post by:
I know this is probably an easy question. But in VB.Net when you instantiate a fontstyle object, the parameter for fontstyle, if you wanted it to be Bold and Italic, you would enter "FontStyle.Bold...
1
by: xiaomitao | last post by:
Hi all, I am having this error, Font 'Aharoni' does not support style 'Regular'. In my codes, i try to catch the exception but seems like it is not catching it. Any idea why? How can i...
3
by: Dom | last post by:
I want to change the FontStyle in a DataGridView control. But for some reason, Font.Strikeout is read only. The only thing I can think of is to create a new Font with the Strikeout FontStyle. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.