• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

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.
0
Wilder1626
Asked:
Wilder1626
  • 5
  • 5
1 Solution
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now