多行文本框到Datagridview [英] Multiline Textbox to Datagridview

查看:70
本文介绍了多行文本框到Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下外观的多行文本框:

I have a multi-line textbox with this appearance:

A#B
C#
D#E

,我想将我的 datagridview 填充为类似这样的内容:

and I want to populate my datagridview to something like this:

_________
|A|BC|D|E|

我的意思是,我想在出现#"时拆分,但我不想在 datagridview 中使用多行单元格.

I mean, I want to split when there's a "#" , but I don't want multi-line cells in datagridview.

我尝试了以下代码:

Dim sup() As String = TextBox1.Text.Split(vbCr, vbLf, vbTab, " "c, "#")
DataGridView1.Rows.Add(sup(0), sup(1), sup(2),sup(3))

但是它说它超出了范围...谢谢!

but it says it goes outta bounds ... Thanks!

索引超出范围异常"错误.

edit: "Index out of range exception" Error.

如果我将文本框值粘贴到Microsoft Word,它们将如下所示:

If i paste the textbox values to microsoft word they come like this:

推荐答案

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
    If DataGridView1.RowCount = 1 Then DataGridView1.Rows.Clear()
    Call dgvstuff()
    Timer1.Stop()
End Sub


Sub dgvstuff()
    Dim sup2 = TextBox2.Text.Replace("#", "").Replace(">", " "c)
    Dim sup() = sup2.Split(" "c, "#", vbCrLf, vbTab)

    With DataGridView1
        .Rows(0).Cells(0).Value = sup(1).ToString
        .Rows(0).Cells(1).Value = sup(7).ToString
        .Rows(0).Cells(3).Value = sup(4).ToString
    End With
End Sub

我真的不知道为什么,但是它像这样工作.有人知道更好/更清洁的方式吗?Tks

I really don't know why but it works like this. Anyone knows a better/cleaner way? Tks

这篇关于多行文本框到Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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