How to export the contents of a combo box to the datatable? - vbscript

I want to export the contents of a combo box to the local data table so that I can parametrize the test using that value.

You need to get each item from the ComboBox. For example where Window Name and ComboBox Name are the names of your window and ComboBox respectively
comboBox = Window("Window Name").WinComboBox("ComboBox Name");
count = comboBox.GetItemsCount
For i = 0 to count-1
item = comboBox.GetItem(i)
' put the item in the DataTable...
Next
How you output each item, the ' put the item in the DataTable.. line, will depend on your set up.

Related

Delete Record VB2010 w/ TableAdapter

This shouldn't be this hard... But it's late.
I am working on a simple form, and trying to delete a record from a connected DataSource while using a TableAdapter. Here is the SQL for the TableAdapter;
DELETE FROM Main WHERE (ID = ?) AND (tbl_Job_Name = ?)
Main is the table name, only two fields.
I am populating a ComboBox with this data, and I am using a Button to call the Delete() action like this;
Private Sub btnDeleteJob_Click(sender As Object, e As System.EventArgs) Handles btnDeleteJob.Click
Dim deleteJobAdapter As New DCGDataSetTableAdapters.MainTableAdapter
deleteJobAdapter.DeleteQuery(ComboBox2.SelectedIndex, ComboBox2.SelectedText)
End Sub
When I break the code I can see the ID value, but the SelectedText field is blank, and of course when it runs through the record is not deleted. I would ideally like to just pass the ID of the selected record in the ComboBox to delete the record. What am I missing?
Try,
deleteJobAdapter.DeleteQuery(ComboBox2.SelectedIndex, ComboBox2.Text)
SelectedText property:
Gets or sets the text that is selected in the editable portion of a ComboBox.
Text property:
Gets or sets the text associated with this control.
You can use the SelectedText property to retrieve or change the currently selected text in a ComboBox control. However, you should be aware that the selection can change automatically because of user interaction. For example, if you retrieve the SelectedText value in a button Click event handler, the value will be an empty string. This is because the selection is automatically cleared when the input focus moves from the combo box to the button.
When the combo box loses focus, the selection point moves to the beginning of the text and any selected text becomes unselected. In this case, getting the SelectedText property retrieves an empty string, and setting the SelectedText property adds the specified value to the beginning of the text.
When I enter the code;
deleteJobAdapter.DeleteQuery(ComboBox2.SelectedIndex, ComboBox2.Text)
My break point shows the correct text from the record, but I did notice that the ID value is incorrect, the SelectedIndex returns a sequential number of the record itself, starting with "0". So it looks like SelectedIndex does not return the actual ID value...
And back to the original issue, the record selected is still not deleted.
This is what I ended up using;
Dim delJobID = ComboBox2.SelectedValue
Dim delJobRowAdpt As New DCGDataSetTableAdapters.MainTableAdapter
Dim delJobRow As DCGDataSet.MainRow
Dim intDelete As Integer
delJobRow = DCGDataSet.Main.FindByID(delJobID)
delJobRow.Delete()

Set displayed text of HyperLink on RadGrid load

I have a telerik RadGrid that gets populated with data from a SQL database when the grid loads. The first column lists a name, which needs to be a hyperlink to another part of the website. I have tried a couple different options, neither of which gets me the results I need.
The first way I tried was using a GridHyperLinkColumn. However that does not allow me to change the displayed text of the hyperlink programmatically when the grid gets populated with data.
<telerik:GridHyperLinkColumn DataNavigateUrlFields="joblink" DataNavigateUrlFormatString="/Job.aspx?id={0}" Text="JobName">
taskDR.Item("joblink") = dataReader("publicID")
taskDR.Item("joblink").Text = dataReader("name") 'This is what I would like to do
The other option was to use a GridBoundColumn and bind a Hyperlink to it.
<telerik:GridBoundColumn DataField="joblink" UniqueName="joblink">
Dim jobhyperlink As New HyperLink()
jobhyperlink.Text = dataReader("name")
jobhyperlink.NavigateUrl = "/Job.aspx?id=" & dataReader("publicID").ToString()
taskDR.Item("joblink") = jobhyperlink
However instead of displaying the hyperlink in the joblink column, all that displays is "System.Web.UI.WebControls.HyperLink"
I looked into the DataTextField and DataTextFormatString properties of GridHyperLinkColumn, but I couldn't find a way to alter those fields programmatically.
you can try a template column and just place a html tag and use Eval function to bind the things the way you want.
Check out this demo - http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
I finally figured it out.
<telerik:GridHyperLinkColumn UniqueName="joblink" Text="jobname" DataNavigateUrlFields="joblink" DataNavigateUrlFormatString="/Employer/Job.aspx?action=edit&id={0}" DataTextField="jobname" DataTextFormatString="{0}">
Dim taskDT As New DataTable
taskDT.Columns.Add("jID")
taskDT.Columns.Add("jobname") 'You need one column for the DataTextField
taskDT.Columns.Add("joblink") 'and another for the DataNavigateUrlField
While dataReader.Read()
Dim taskDR = taskDT.NewRow()
taskDR.Item("jobname") = dataReader("name")
taskDR.Item("joblink") = dataReader("publicID")

How to get all the values selected in a multiselect ListBox in vb6?

I have a ListBox on my vb6 project and I've set its property to multiselect.
Now, I want to get all of the selected items on my multiselect ListBox and put it in a variable for example, or maybe on a multiline textbox. I just wanted to get the multiselected values.
Unfortunately you must loop through all elements. Here is some sample code:
Dim k As Long
Dim s As String
For k = 0 To List1.ListCount - 1
If List1.Selected(k) Then
s = List1.List(k)
' ... do something
End If
Next

Passing value from GridView selected value to DropDownList Default Value

How do I pass a selected value from GridView to a DropDownList default value. The DDL always show the first item from the table. I want to be able to display the first item as the value from another GridView (selected Item).
Thank you in advance for your help.
On your DataGridview Event where you get the selected value add.
//YOur Bindinding on Dropdown
drpdown.DataSource = //;
drpdown.DataTextField = "YourTablecolumn";
drpdown.DataBind();
string gvalue = //gridselected value;
drpdown.Items.Insert(0, new ListItem(""+ gvalue +"", "0"));
drpdown.SelectedIndex = 0;
Hope this help.
Regards

List view Double click Event

Using VB6
Listview
ID Name
001 Raja
002 Ramu
003 Sajee
..
…
Code
Private Sub listview1_DblClick()
If Not (listview1.SelectedItem Is Nothing) Then
Textbox1.text = listview1.selectedItem(0)
Textbox2.text = listview1.SelectedItem(1)
End If
End Sub
Above code is not showing the values in the text box
How to show the list view row values in the text box.
Need VB6 Code Help
The ListView SelectedItem property does not return a collection of items selected on your ListView, so therefore you can't explicitly get the first selected item, the second selected item, etc. You will need to loop through all ListItems in your ListView and check if each is selected. If it is, do what you want to do.
One problem I see with your sample code is you're using the ListView DblClick event. I might be wrong, but it looks like whenever it fires only one ListView item can be selected (the one that fired the event). A solution for this is to put your code into a new procedure. Here's one that should work:
Private Sub GetSelectedItems()
' Make sure exactly two items are selected on our ListView.
If (CheckListViewSelectedItemCount(listview1, 2)) Then
Dim blnFoundFirstItem As Boolean
blnFoundFirstItem = False
Dim i As Integer
' Find out which items are selected.
For i = 1 To listview1.ListItems.Count
If (listview1.ListItems(i).Selected) Then
' Assign the Text of the 'first' selected item to Textbox1.Text.
If (Not blnFoundFirstItem) Then
Textbox1.Text = listview1.ListItems(i).Text
blnFoundFirstItem = True
' Assign the Text of the 'second' selected item to Textbox2.Text.
Else
Textbox2.Text = listview1.ListItems(i).Text
End If
End If
Next i
Else
MsgBox "You need to select two items."
End If
End Sub
I'm not sure in which order ListItems are iterated through in my For loop. It's possible that what would be assigned to Textbox1.Text in my code you might want to assign to Textbox2.Text.
Your code required at that at least two items are selected on the ListView. I don't know if VB6 has a way to return the number of selected items so I wrote a small function that does this:
' Return True if the passed ListView control has a number of selected items that's equal to the intExpectedItemCount parameter.
Private Function CheckListViewSelectedItemCount(listView As listView, intExpectedItemCount As Integer) As Boolean
Dim intSelectedItemCount As Integer
intSelectedItemCount = 0
Dim i As Integer
For i = 1 To listView.ListItems.Count
If (listView.ListItems(i).Selected) Then
intSelectedItemCount = intSelectedItemCount + 1
End If
Next i
CheckListViewSelectedItemCount = (intSelectedItemCount = intExpectedItemCount)
End Function
I dont have vb6 at hand and its been a while since I used it, but if memory serves me right:
ListView1.SelectedItem will return you a ListViewItem which gives you a Text property along with SubItems property that gives you access to associated columns as an array.

Resources