chadmanvb
asked on
show string in 2 columns
I use a form as a popup box, but the text I display looks messing. How can I seperate the 2 values so it looks like its in 2 columns before I send the string to may form? Here is what the text looks like:
DISKDEFRAG 0100_COR_00
DOTNETFRAMEWKRE 0200_COR_00
DOTNETFRAMEWORK 0011_COR_00
DOTNETFW30 0300_COR_00
EFEMERALPORTCFG 0100_COR_00
ESDMENUPICK 0001_COR_02
DISKDEFRAG 0100_COR_00
DOTNETFRAMEWKRE 0200_COR_00
DOTNETFRAMEWORK 0011_COR_00
DOTNETFW30 0300_COR_00
EFEMERALPORTCFG 0100_COR_00
ESDMENUPICK 0001_COR_02
say you have line and use this
dim a = line.split(" ")
dim nl = a(0).padRight(20) & a(1)
send nl
dim a = line.split(" ")
dim nl = a(0).padRight(20) & a(1)
send nl
Still around?
ASKER
Yep, I will check it out mon/tues at work
ASKER
say you have line and use this
dim a = line.split(" ")
dim nl = a(0).padRight(20) & a(1)
send nl
This splits the string, but does not make the columns even
Column1.Text = Left$(StringToSplit.Text, InStr(1, StringToSplit.Text, " ") - 1)
Column2.Text = Mid$(StringToSplit.Text, InStr(1, StringToSplit.Text, " ") + 1)
I could not get this to work. I tried to use:
arrServiceList.Sort(arrSer
Dim strService As String = ""
Dim strServiceTotal As String = ""
For Each line As String In arrServiceList 'loop array for the string
strService = line.ToString
Dim strCol1 As String = ""
Dim strCol2 As String = ""
strCol1 = Left$(strService, InStr(1, strService, " ") - 1)
strCol2 = Mid$(strService, InStr(1, strService, " ") + 1)
strService = line.Trim.ToString
strServiceTotal = strServiceTotal & strService & vbCrLf
ASKER
strCol1 = Left$(strService, InStr(1, strService, " ") - 1)
Opps hit send to fast, but this is the line that errors. It does not like the left.
Opps hit send to fast, but this is the line that errors. It does not like the left.
Are you printing these lines? Or showing in some control?
ASKER
I will pass the strServiceTotal string to a new form to print as a popup box
>print as a popup box
You mean show as a popup form? What controls are you using on this form?
You mean show as a popup form? What controls are you using on this form?
ASKER
Yep, here is what I'm doing
Dim arrServiceList() As String = (GetPage(WebString))
arrServiceList.Sort(arrSer viceList)
Dim strService As String = ""
Dim strServiceTotal As String = ""
For Each line As String In arrServiceList 'loop array for the string
strService = line.ToString
Dim strCol1 As String = ""
Dim strCol2 As String = ""
strCol1 = Left(strService, InStr(1, strService, " ") - 1)
strCol2 = Mid(strService, InStr(1, strService, " ") + 1)
strService = line.Trim.ToString
strServiceTotal = strServiceTotal & strService & vbCrLf
Next line
'display list on popup form
Dim frmPopupSeviceList As New frmPopSearch(strServiceTot al)
If frmPopupSeviceList.ShowDia log() = Windows.Forms.DialogResult .Cancel Then
' the cancel button was clicked
Exit Sub
End If
I guess I could use a listbox. But I was hopping there would be an easy way to the textbox look like 2 columns. so
DISKDEFRAG 0100_COR_00
DOTNETFRAMEWKRE 0200_COR_00
DOTNETFRAMEWORK 0011_COR_00
DOTNETFW30 0300_COR_00
EFEMERALPORTCFG 0100_COR_00
ESDMENUPICK 0001_COR_02
would look like
DISKDEFRAG 0100_COR_00
DOTNETFRAMEWKRE 0200_COR_00
DOTNETFRAMEWORK 0011_COR_00
DOTNETFW30 0300_COR_00
EFEMERALPORTCFG 0100_COR_00
ESDMENUPICK 0001_COR_02
Dim arrServiceList() As String = (GetPage(WebString))
arrServiceList.Sort(arrSer
Dim strService As String = ""
Dim strServiceTotal As String = ""
For Each line As String In arrServiceList 'loop array for the string
strService = line.ToString
Dim strCol1 As String = ""
Dim strCol2 As String = ""
strCol1 = Left(strService, InStr(1, strService, " ") - 1)
strCol2 = Mid(strService, InStr(1, strService, " ") + 1)
strService = line.Trim.ToString
strServiceTotal = strServiceTotal & strService & vbCrLf
Next line
'display list on popup form
Dim frmPopupSeviceList As New frmPopSearch(strServiceTot
If frmPopupSeviceList.ShowDia
' the cancel button was clicked
Exit Sub
End If
I guess I could use a listbox. But I was hopping there would be an easy way to the textbox look like 2 columns. so
DISKDEFRAG 0100_COR_00
DOTNETFRAMEWKRE 0200_COR_00
DOTNETFRAMEWORK 0011_COR_00
DOTNETFW30 0300_COR_00
EFEMERALPORTCFG 0100_COR_00
ESDMENUPICK 0001_COR_02
would look like
DISKDEFRAG 0100_COR_00
DOTNETFRAMEWKRE 0200_COR_00
DOTNETFRAMEWORK 0011_COR_00
DOTNETFW30 0300_COR_00
EFEMERALPORTCFG 0100_COR_00
ESDMENUPICK 0001_COR_02
ASKER
opps the spacing did not turn on right on this form, but I guess you get the idea. I just want both columns lined up so it looks nice and is easier to read.
You have multiple options. If the number of items is known and limited then you could simply use the labels. Otherwise you could either use a multicolumn ListView control or a DataGridView. You can populate a DataTable on main form and then pass it to popup form which would simply set the DataTable as the DataSource of the DataGridView. Let me know which way you want to go and i can provide relevant code examples.
ASKER
I have never used a DataGridView, but have used ListView. Could you show me how pass this from my main form to the popup form?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you were to use a DataGridView then
Popupform:
DataGridView1.DataSource = dTable 'just a single line of code!
Popupform:
DataGridView1.DataSource = dTable 'just a single line of code!
ASKER
Ok, I think we are close. I still see a couple problems that I guess I am doing wrong.
arrServiceList.Sort(arrSer viceList)
Dim strService As String = ""
Dim strServiceTotal As String = ""
Dim dTable As New DataTable
dTable.Columns.Add("Column 1", GetType(String))
dTable.Columns.Add("Column 2", GetType(String))
Dim drow As DataRow = dTable.NewRow
For Each line As String In arrServiceList 'loop array for the string
line.Split(","c)
'strService = line.Trim.ToString.Split(" ,"c)
drow(0) = line(0)
drow(1) = line(1)
dTable.Rows.Add(drow)
'strServiceTotal = strServiceTotal & strService & vbCrLf
Next line
frmPopSearch.dTable = dTable 'this is not reconized. does not like the dTable after it. frmPopSearch is the name of my new form
'Dim frmPopupSeviceList As New frmPopSearch(strServiceTot al)
And for on my popup form I have the following error:
Public Class frmPopSearch
Public Sub New(ByVal DisplayText As String)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'TextBox1.Text = DisplayText
'TextBox1.Select(0, 0) 'this will get set focus on textbox backgroud so the text will not be highlighted
'*******************code does not like the dTable, I guess it does not see it from my original form?
For i As Integer = 0 To dTable.Rows.Count - 1
Dim lItem As New ListViewItem(dTable.Rows(i ).Item(0)) 'Set the listview to details mode and add the columns as you want
lItem.SubItems.Add(dTable. Rows(i).It em(1))
ListView1.Items.Add(lItem)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub frmPopSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'********************I have the same error below if I put the code here
'For i As Integer = 0 To dTable.Rows.Count - 1
' Dim lItem As New ListViewItem(dTable.Rows(i ).Item(0)) 'Set the listview to details mode and add the columns as you want
' lItem.SubItems.Add(dTable. Rows(i).It em(1))
' ListView1.Items.Add(lItem)
'Next
End Sub
End Class
arrServiceList.Sort(arrSer
Dim strService As String = ""
Dim strServiceTotal As String = ""
Dim dTable As New DataTable
dTable.Columns.Add("Column
dTable.Columns.Add("Column
Dim drow As DataRow = dTable.NewRow
For Each line As String In arrServiceList 'loop array for the string
line.Split(","c)
'strService = line.Trim.ToString.Split("
drow(0) = line(0)
drow(1) = line(1)
dTable.Rows.Add(drow)
'strServiceTotal = strServiceTotal & strService & vbCrLf
Next line
frmPopSearch.dTable = dTable 'this is not reconized. does not like the dTable after it. frmPopSearch is the name of my new form
'Dim frmPopupSeviceList As New frmPopSearch(strServiceTot
And for on my popup form I have the following error:
Public Class frmPopSearch
Public Sub New(ByVal DisplayText As String)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'TextBox1.Text = DisplayText
'TextBox1.Select(0, 0) 'this will get set focus on textbox backgroud so the text will not be highlighted
'*******************code does not like the dTable, I guess it does not see it from my original form?
For i As Integer = 0 To dTable.Rows.Count - 1
Dim lItem As New ListViewItem(dTable.Rows(i
lItem.SubItems.Add(dTable.
ListView1.Items.Add(lItem)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub frmPopSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'********************I have the same error below if I put the code here
'For i As Integer = 0 To dTable.Rows.Count - 1
' Dim lItem As New ListViewItem(dTable.Rows(i
' lItem.SubItems.Add(dTable.
' ListView1.Items.Add(lItem)
'Next
End Sub
End Class
Change this
Public Class frmPopSearch
to this
Public Class frmPopSearch
Public dTable as DataTable
Notice that i created this variable in the popup form. You need this at the class level and it needs to be public/friend so that you can set it from the main form.
Public Class frmPopSearch
to this
Public Class frmPopSearch
Public dTable as DataTable
Notice that i created this variable in the popup form. You need this at the class level and it needs to be public/friend so that you can set it from the main form.
ASKER
still have 2 errors.
first one is how I am calling the pop form. I am using
frmPopSearch.dTable = dTable 'In popup form class, declare a public variable called dTable of type DataTable at class level
when I just passed a string before I used the following and it worked.
Dim frmPopupSeviceList As New frmPopSearch(strServiceTot al)
The second error I see it the line on the new popup form:
Dim lItem As New ListViewItem(dTable.Rows(i ).Item(0))
This gives me the following error:
Error 7 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(group As System.Windows.Forms.ListV iewGroup)' : Argument matching parameter 'group' narrows from 'Object' to 'System.Windows.Forms.List ViewGroup' .
'Public Sub New(items() As String)': Argument matching parameter 'items' narrows from 'Object' to '1-dimensional array of String'.
'Public Sub New(text As String)': Argument matching parameter 'text' narrows from 'Object' to 'String'. C:\Temp\pkg_add\frmPopSear ch.vb
I do have a listview created with 2 columns labled in detail.
Any ideas?
first one is how I am calling the pop form. I am using
frmPopSearch.dTable = dTable 'In popup form class, declare a public variable called dTable of type DataTable at class level
when I just passed a string before I used the following and it worked.
Dim frmPopupSeviceList As New frmPopSearch(strServiceTot
The second error I see it the line on the new popup form:
Dim lItem As New ListViewItem(dTable.Rows(i
This gives me the following error:
Error 7 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(group As System.Windows.Forms.ListV
'Public Sub New(items() As String)': Argument matching parameter 'items' narrows from 'Object' to '1-dimensional array of String'.
'Public Sub New(text As String)': Argument matching parameter 'text' narrows from 'Object' to 'String'. C:\Temp\pkg_add\frmPopSear
I do have a listview created with 2 columns labled in detail.
Any ideas?
1) Remove the constructor from the class and change the code to look like this
Dim frm As New FrmPopSearch
frm.DTable = dTable
frm.ShowDialog
2) Change
Dim lItem As New ListViewItem(dTable.Rows(i ).Item(0))
to
Dim lItem As New ListViewItem(CType(dTable. Rows(i).It em(0), String))
Dim frm As New FrmPopSearch
frm.DTable = dTable
frm.ShowDialog
2) Change
Dim lItem As New ListViewItem(dTable.Rows(i
to
Dim lItem As New ListViewItem(CType(dTable.
ASKER
On step one I still get an error calling the form:
Error 5 Argument not specified for parameter 'DisplayText' of 'Public Sub New(DisplayText As String)'.
am I missing somthing still?
Looks like the error on step 2 worked.
Error 5 Argument not specified for parameter 'DisplayText' of 'Public Sub New(DisplayText As String)'.
am I missing somthing still?
Looks like the error on step 2 worked.
As i said, remove the constructor from the popup form class
Remove this method
Public Sub New(DisplayText As String)
Remove this method
Public Sub New(DisplayText As String)
Or Replace it with
Public Sub New(dTable as DataTable)
Public Sub New(dTable as DataTable)
ASKER
I made the change, but that just gave me another error. Here is what I have my main form
For Each line As String In arrServiceList 'loop array for the string
line.Split(","c)
'strService = line.Trim.ToString.Split(" ,"c)
drow(0) = line(0)
drow(1) = line(1)
dTable.Rows.Add(drow)
'strServiceTotal = strServiceTotal & strService & vbCrLf
Next line
'display list on popup form
Dim frm As New frmPopSearch '*********************i get an error here Argument not specified for parameter 'dTable' of 'Public Sub New(dTable As System.Data.DataTable)
frm.dTable = dTable
frm.ShowDialog()
If frm.ShowDialog() = Windows.Forms.DialogResult .Cancel Then
' the cancel button was clicked
Exit Sub
End If
On my pop form I have:
Public Class frmPopSearch
Public dTable As DataTable
Public Sub New(ByVal dTable As DataTable)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
For i As Integer = 0 To dtable.Rows.Count - 1
Dim lItem As New ListViewItem(CType(dtable. Rows(i).It em(0), String))
lItem.SubItems.Add(dtable. Rows(i).It em(1))
ListView1.Items.Add(lItem)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
Also thanks for all the help! I know i have to be close:-)
For Each line As String In arrServiceList 'loop array for the string
line.Split(","c)
'strService = line.Trim.ToString.Split("
drow(0) = line(0)
drow(1) = line(1)
dTable.Rows.Add(drow)
'strServiceTotal = strServiceTotal & strService & vbCrLf
Next line
'display list on popup form
Dim frm As New frmPopSearch '*********************i get an error here Argument not specified for parameter 'dTable' of 'Public Sub New(dTable As System.Data.DataTable)
frm.dTable = dTable
frm.ShowDialog()
If frm.ShowDialog() = Windows.Forms.DialogResult
' the cancel button was clicked
Exit Sub
End If
On my pop form I have:
Public Class frmPopSearch
Public dTable As DataTable
Public Sub New(ByVal dTable As DataTable)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
For i As Integer = 0 To dtable.Rows.Count - 1
Dim lItem As New ListViewItem(CType(dtable.
lItem.SubItems.Add(dtable.
ListView1.Items.Add(lItem)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
Also thanks for all the help! I know i have to be close:-)
Ok. I thought you would know that if you changed the constructor to accept a datatable then you would use it like this
Dim frm As New frmPopSearch(dTable)
But i think you should remove the constructor to avoid confusion.
Dim frm As New frmPopSearch(dTable)
But i think you should remove the constructor to avoid confusion.
ASKER
I got it working! Thanks again for all of your patience and time.
Column2.Text = Mid$(StringToSplit.Text, InStr(1, StringToSplit.Text, " ") + 1)