格式化datagridview单元格的一部分字符串 [英] Formatting part of a String for a datagridview cell

查看:104
本文介绍了格式化datagridview单元格的一部分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我需要帮助.
我想在vb.net中为DataGridViewCel格式化一部分字符串.

我正在做的是在datagridview中输入一个人的详细信息.
因此,应该使用不同的字体来格式化数据,然后将其显示在DGV单元上.
因此,基本上我的数据由名称",详细信息1 ..."和详细信息2 ..."组成.
我的名称"必须为粗体,并且其大小必须大于其他文本.
"Details 1"和"Details 2"具有相同的大小和字体.
所有这3个都来自3条不同的线.

所以我到目前为止所做的...
1.我已在DGV中将multiline属性设置为true

Hi!
I need help.
I want to format part of a String for a DataGridViewCel in vb.net.

The thing that I''m doing is, inputting details of a person in a datagridview.
So the data is supposed to be formatted with different fonts and then displayed on the DGV cell.
SO bascially my data consists of "Name", "Details 1..." and "Details 2..."
My "Name" has to be bold and the size of that has to be larger than the other text.
"Details 1" and "Details 2" are of the same size and font.
All these 3 come on 3 different lines.

So what I''ve done till now...
1. I''ve set multiline property to true in the DGV

Private Sub DGV_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles Me.CellFormatting
        e.CellStyle.WrapMode = DataGridViewTriState.True
        Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        Me.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
End Sub



2.我创建了一个列,并在其中添加了行



2. I''ve created a column and added rows into it

Me.Rows.Add(PName & Environment.NewLine & Assembly & Environment.NewLine & Sex & ", " & Group & ", " & Custom)


(所有变量均为String类型)
您会看到,换行符变量将数据的三个区域分开.

问题:如何仅将"PName"设置为不同的字体,不同的大小并将其设置为粗体并使其余字符串保持原样?


(All variables are of String type)
You see, the Newline variables separate the three regions of data.

Question: How do I set only "PName" to a different font, different size and make it bold and leave the rest of the string as it is?

推荐答案

如何?你没有!

它的工作原理与普通TextBox控件完全相同.单元格中只能有一种字体.

您不能使用默认的TextBox列在同一单元格中使用多种字体,大小和格式样式.为了实现这一点,您必须使用RichTextBox控件而不是TextBox控件来设计自己的DataGridViewTextBoxColumn版本.

警告!创建自己的自定义DGV列类型并不容易!有很多需要掩盖的地方.您可以先浏览
How? You don''t!

It works exactly the same as a normal TextBox control. You can only have a single font in a cell.

You cannot use multiple fonts, sizes and formatting styles in the same cell using the default TextBox column. In order to implement this, you''d have to design your own version of a DataGridViewTextBoxColumn using a RichTextBox control instead of a TextBox control.

Warning! Creating your own custom DGV column types is NOT easy to do! There''s a lot of ground to cover. You can start by going over this list[^] of articles on the subject.


For Each gr1 As GridViewRow In gridview1.Rows
gr1.Cells(0).Font.Bold = True
gr1.Cells(0).Font.Size = 12
gr1.Cells(1).Font.Bold = False
gr1.Cells(1).Font.Size = 10
gr1.Cells(2).Font.Bold = False
gr1.Cells(2).Font.Size = 10
Next


gridview1 是gridview的名称
它在网格视图中编写Binddata的代码


gridview1 is the name of gridview
It write the Code of Binddata in Grid View


这篇关于格式化datagridview单元格的一部分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆