富文本框中的表格 [英] Table in richtextbox
问题描述
在我之前的问题中,我发布了一个在富文本框中添加表格的代码(实际上不是,只是将数据从 dgvw 添加到richtxtbx)..代码是:
For i As Integer = 0 To dg2.Rows.Count - 2SendMail.bodytxt.Text = SendMail.bodytxt.Text + "-"对于 j 作为整数 = 0 到 dg2.Columns.Count - 1尝试SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbTab + dg2.Rows(i).Cells(j).Value.ToString() + vbTabCatch ex 作为例外结束尝试SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLfSendMail.bodytxt.Text = SendMail.bodytxt.Text + "--------------------------------------------" + vbLfSendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf下一个下一个
结果如下:
--------------------------------------------88795446-----------------------------------------先生.-----------------------------------------赖扬-----------------------------------------拉希德-----------------------------------------男性-----------------------------------------
我希望你明白问题出在哪里..每个单元格的值都被添加到一个新行中..我如何生成这样的视图:
HEADER TEXT HEADER TEXT HEADER TEXT------------------------------------------------ABC先生 0123456789------------------------------------------------DEF先生 987654321------------------------------------------------吉先生 898989898
我的意思是一行的所有单元格值都在一行中...下一行将用破折号填充.....然后下一行将包含下一行的单元格值....>
我知道我的代码是正确的,但也许我遇到了一些排列代码"的问题...或者这是因为我的富文本框大小而发生的?我这么想的原因是因为当我从包含 2/3 列的 dgvw 添加数据时,它按预期工作..那么如何修复它或实现我正在寻找的外观?
也许这会有所帮助
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "---------------------------------------------------------------------------------------------------" + vbLf对于 i As Integer = 0 To dg2.Rows.Count - 1对于 j 作为整数 = 0 到 dg2.Columns.Count - 1尝试SendMail.bodytxt.Text = SendMail.bodytxt.Text + "• " + dg2.Rows(i).Cells(j).Value.ToString() + "•"Catch ex 作为例外结束尝试下一个SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLfSendMail.bodytxt.Text = SendMail.bodytxt.Text + "------------------------------------------------------------------------------------------" + vbLf下一个
这甚至可能会让您看起来更好.您必须根据需要添加尽可能多的-"(破折号).如果有效,请告诉我
In my previous question, I posted a code that adds a table (not actually, just adds data to the richtxtbx from dgvw) in a rich text box ..The code is:
For i As Integer = 0 To dg2.Rows.Count - 2
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "-"
For j As Integer = 0 To dg2.Columns.Count - 1
Try
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbTab + dg2.Rows(i).Cells(j).Value.ToString() + vbTab
Catch ex As Exception
End Try
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "--------------------------------------------" + vbLf
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf
Next
Next
The results look like this :
--------------------------------------------
88795446
--------------------------------------------
Mr.
--------------------------------------------
Raiyan
--------------------------------------------
rashid
--------------------------------------------
Male
--------------------------------------------
I hope you see what the problem is.. Each cell's value is being added in a new line.. How do I generate a view like this:
HEADER TEXT HEADER TEXT HEADER TEXT
------------------------------------------------
Mr. ABC 0123456789
------------------------------------------------
Mr. DEF 987654321
------------------------------------------------
Mr. GHI 898989898
I mean all cell values of a row would be in one line... The next line would be filled with dashes..... Then the next will contain the cell values of the next rows....
I know my code is correct but maybe I am having some "ARRANGING THE CODE" issue... Or is this happening because of my rich textbox size? The reason why I'm thinking so is because when I add data from a dgvw containing 2/3 columns, it works as expected.. So how to fix it or achieve the look I am looking for?
maybe this would help
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "------------------------------------------------------------------------------------------" + vbLf
For i As Integer = 0 To dg2.Rows.Count - 1
For j As Integer = 0 To dg2.Columns.Count - 1
Try
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "• " + dg2.Rows(i).Cells(j).Value.ToString() + " •"
Catch ex As Exception
End Try
Next
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "------------------------------------------------------------------------------------------" + vbLf
Next
This might even give you a better look.You must add as many "-"(dashes)as you need.Let me know if it worked
这篇关于富文本框中的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!