Visual Basic DataGridView cell = TextBox1 row value

Hi

I have this TextBox1 with a multiline settings.

When i select a specific row inside the textBox1,  it would inter in the DataGridView1 second cell the TextBox1 value starting at space 20 and for a length of 27 characters.  So from space 20 to 47.
example:

If i have on the row:O204H31165          00020457511M               4010    

Space 20 to 47 would be: 00020457511M              

How can I do that?

DataGridView1.Item(1, 0).Value = Me.TextBox1.Text

Open in new window


TextBox to DataGridViewThanks for your help.
LVL 11
Wilder1626Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Can you attach your project?
0
Wilder1626Author Commented:
Here is a sample of the app.
EDI-analysis-application.zip
0
Martin LissOlder than dirtCommented:
Sorry, I thought this was VB6 which apparently it's not and so I can't help.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Wilder1626Author Commented:
Hi MartinLiss
How would you do it with VB6?

Here is a sample with VB6
EDI-app-VB6.zip
0
Martin LissOlder than dirtCommented:
Change

MSHFlexGrid1.TextMatrix(1, 1) = Text1.Text

to

MSHFlexGrid1.TextMatrix(1, 1) = Mid$(Text1.Text, 21, 27)

Is that what you mean?
0
Wilder1626Author Commented:
Almost.
If i put my cursor on the 3 row of the TextBox Multiple, it should send  the value from that specific row into the MSHFlexgrid. Ex: Mid$(Text1.line:3, 21, 27)

If i click on another row, still in the same TextBox, it would give me the result of that specific row again in my MSHFlexgrid.

Is that possible?

I'm trying to find another way, but no idea yet. Maybe with a ListBox.
0
Martin LissOlder than dirtCommented:
This code will display the text of the selected line and you can modify and use what's in strBuffer in my code above. In other words

MSHFlexGrid1.TextMatrix(1, 1) = Mid$(strBuffer, 21, 27)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
                                     ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINELENGTH = &HC1
Private Const EM_GETLINE = &HC4

Private Sub Command1_Click()

Dim lngSelectedLine As Long
Dim lngLength As Long
Dim lngFirstCharPos As Long
Dim strBuffer As String

' Determine selected line number (Starts at 0)
lngSelectedLine = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, 0)
lngFirstCharPos = SendMessage(Text1.hwnd, EM_LINEINDEX, lngSelectedLine, 0&)
' length of line
lngLength = SendMessage(Text1.hwnd, EM_LINELENGTH, lngFirstCharPos, 0&)

strBuffer = Space(lngLength)
' get line text
Call SendMessage(Text1.hwnd, EM_GETLINE, lngSelectedLine, ByVal strBuffer)
MsgBox strBuffer

Open in new window

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wilder1626Author Commented:
wow, this is awesome!!!!
Thank you so much. I will play with it going forward.

    Dim lngSelectedLine As Long
    Dim lngLength       As Long
    Dim lngFirstCharPos As Long
    Dim strBuffer       As String

    ' Determine selected line number (Starts at 0)
    lngSelectedLine = SendMessage(EDI_CODE.hwnd, EM_LINEFROMCHAR, -1, 0)
    lngFirstCharPos = SendMessage(EDI_CODE.hwnd, EM_LINEINDEX, lngSelectedLine, 0&)
    ' length of line
    lngLength = SendMessage(EDI_CODE.hwnd, EM_LINELENGTH, lngFirstCharPos, 0&)

    strBuffer = Space(lngLength)
    ' get line text
    Call SendMessage(EDI_CODE.hwnd, EM_GETLINE, lngSelectedLine, ByVal strBuffer)
    'MsgBox strBuffer

    EDI_DETAILS.TextMatrix(1, 1) = Mid$(strBuffer, 21, 27)

Open in new window

0
Wilder1626Author Commented:
wow, this is awesome!!!! Like always!!! :)
0
Martin LissOlder than dirtCommented:
And like always, you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.