DataList Control in vb.net windows application forms - vb.net

I am upgrading my application from vb6 to vb.net.
I used to populate my data in datalist control in vb6 forms. I am not finding it in vb.net windows form application. Which one control is the equivalent to it?
How can i list my data in that control?
just like:
I had a table with data like id, name
I want the name should be the displayed column and id the bound column? how can i do that

I'm not exactly sure but I think you're looking for a ListBox. You create a class with 2 members and a property for each (suggested property names ID and Name), create a list of them and put all your data in there and then just set the 'ListBox.DisplayMember' to "Name" and ListBox.ValueMember to "ID".
The MSDN page for ListControl.DisplayMember has a full sample showing how to do it as can be seen here.
Though I'd suggest that you use a List(Of YourClass) rather than the ArrayList in the sample.

Related

How to filter a GridView in Visual Basic WITHOUT any Database

I made a lot of research on internet, and have found a lot of tutorials about "how to filter/sort a GridView" in VB.NET, BUT, all of theme are using a Database.
In my case I only have these:
MP3Song : a custom class with some property like "Title","Artist","Duration", etc.
A List(Of MP3Song) : which is linked to my GridView like this:
myMP3Collection = New List(Of MP3Song.MP3Song)
mp3SongBinndingSource.DataSource = myMP3Collection
I'm using a List(Of ...) because when I populate this list, I do some verification and I'm likely to modify some "already added" data. And it is very easy for me :
myMP3Collection.ElementAt(i).Extd = True 'Extd is a Boolean property, others are string...
During my research I have seen that I should use a DataSet (easier to filter/sort a GridView).
Here is my question :
Should I make a DataSet based on my collection (populated by a For Each which scan my List, and add all item in row in my table
Or should I try to directly populate a DataSet instead of a ListOf(). If 2nd choice is better, is that easy as with collection to access and modify an element in a row ?
Thanks for your time
Tim Van Wassenhove's FilterList is just what you need. He extends the List(Of T) into SortableBindingLists and FilterLists.
While his code is C#, you can easily use an on-line converter. Or, create a C# .DLL, use the code, and reference that .DLL from your VB.NET app.

Auto Find and display objects when input keywords in VB

I'm a newbie in VB form programming. I got a task today, it seems so hard for me. basically, I have 2 forms named: Form1 and Form2. Form1 use for management info of students such as: student's code, name, phone number, etc..i have a button in Form1, when I press it, Form2 will be invoked. i have completed it.
the problem is: in Form2, I just have 1 textbox and 1 listbox. how should it work? => when I type in textbox with 1 keyword relate to info of students in Form1, Listbox will display automatically all of students's name that relate to the keyword I typed . I didn't know any idea to do it automatically. anyone can help me please give me a way. Thanks you so much.
Based on the solution which you use to store list of students there could be different possible solutions. But for all of them, using TextChanged event of that TextBox you can set the filter for the main list which contains students.
If you use a DataTable to store students, you can use DefaultView.RowFilter of the DataTable:
dt.DefaultView.RowFilter = string.Format("Name Like '{0}*'", TextBox1.Text)
Also if you are using generic lists for storing students, you can use linq to do so:
var data = list.Where(Function(s) s.Name.StartsWith(x.Name.StartsWith(TextBox1.Text)) _
.ToList()
listBox1.DataSource = New BindingList(Of Student)(data)
Also if interaction between forms was an issue for you, take a look at this post.

Microsoft Access 2013 Form Objects

I have a database that was create in Access 2010. We recently updated our systems to Access 2013. In Access 2010 I have no errors accessing a form object with
Form_frmName.txtFieldName.Value
However, when using Access 2013 I get a runtime 2424 error stating that "The expression you entered has a field, control, or property name that Microsoft Access can't find. I am accessing from a module.
The module sets these fields visible using
With Form_frmName
.txtFieldName.Visible = True
End With
before attempting to access them.
Has there been any changes in the way form objects are accessed between 2010 and 2013? Is this an issue others have faced?
In Response to #WayneGDunn's questions below
QUOTE:
I need to know exactly what and how you are using this.
1. You have a bound textbox named 'txtFieldName' on a form. As #brad asked, is there a subform, and if so, is this field on the subform?
2. You said the code is in a module, but is the code in the form where the field is defined?
3. Please explain where/what form 'frmQAtab' is (you said your form name was 'frmName', so what is the other, how related?)
4. Is the code in an event? Can you share the entire subroutine?
5. Have you tried creating a dummy query and using the builder to reference the field?
RESPONSE:
1. I have a form (frmMain) with multiple tabbed pages. frmName is one of those tabs, containing the bound field txtFieldName.
2. The module is run from the form the field is in.
3. My apologies frmQAtab is frmName, I just neglected to make that generic in my copy-paste.
4. The event is a button click. The button click runs a sub from a module. That sub makes visible the fields, runs a query based on user input (two date fields), populates the bound fields with the returned record set, then attempts to access them for processing (another query is run to process a complete other set of fields). To post the entire subroutine would be a bit more than I would ask you to chew on. This is legacy code I'm trying to fix, and it's rather large.
5. I have not tried a dummy query. Access is not my field (I'm mainly a C#, scripting, guy.) Is there some suggestions in this area you could give?
One of the following references to your fields should work. I created a form (named 'frmMain'), then created a Tab Control with two tabs. On the first tab, I inserted another form (named 'frm3197'). I also created a text box on the tab control named 'txtFieldName' AND in form 'frm3197'. From a button click on 'frmMain', the following will reference each of those fields.
Private Sub cmdButton1_Click()
Forms![frmMain]![txtFieldName] = Now()
Forms![frmMain]![frm3197].Form![txtFieldName] = Now()
End Sub

Syntax for SharePoint 2010 BCS URL Action to populate New form

Have seen several posts with solutions for native SharePoint lists, including the very useful SPUtility.js (only for native SharePoint lists). But nothing to pass a value from a BCS list to a new BCS list. The Query string filter will not connect on the New form (no web part to connect it to) and does me no good on the lists page (already have that working).
A "go write custom code for everything" is not a solution for me.
There should be a way to 1) pass the value in the URL (ideal - what's the syntax?) or 2) make some other simple change, perhaps to the select list for the item -- I just can't find it. Have seen quite a few posts with similar questions. The Microsoft documentation is not useful and there are more questions on the "social" topics than answers.
Here's what I have:
I have a BCS list (sends item) tied to a BCS related list (receives item).
I have an action on the related list (ECT) to create a new item. Works fine with no parameters. I get a blank new form. The new form allows me to enter two items and choose two items (exactly as intended).
What I would like to have is the necessary ?something=something string so that my user does not have to select one of the choice items (MNumber - set as a key / required value)
User selects "New" from Actions.
Form Opens
MNumber is automatically filled in based on the MNumber of the current item displayed in the BCS related list.
The string I supply is accepted. Does nothing.
/intake/Lists/ContactsList/NewForm.aspx
/intake/Lists/ContactsList/NewForm.aspx?MNumber=1234
The string I supply is rejected - cannot be saved or insufficient values.
/intake/Lists/ContactsList/NewForm.aspx?MHICNumber={$MHICNumber}
Have also tried passing a string to one of the text fields (instead of the select field). Can't get that to work either. I've spent quite a few hours with the various boards. Nothing helpful.
Would also be nicer if I could set the New form to display in a pop-over window (as it does when I select New from the list view). Opening a new browser window is hokey and replacing the existing one is a navigation pain for the user.
Have this working ... Thanks to Kit Menke!
Created an Action on the External Content Type in the BCS....
/intake/Lists/ContactsList/NewForm.aspx?IDnumber={0}&Source=/intake/scheduling.aspx
where
parameter property 0 is the IDNumber from the ECT
The NewForm.aspx was edited to add a hidden content editor web part with references to three scripts Kit wrote - two supporting and one that sets the values.
http://site/list/NewForm.aspx?toolpaneview=2
User selects the Action on the displayed ECT list
Action uses the URL to go to the New page with the data
Kit's script adds the data to the form and puts in the date and time.
Note: The ID field needs to be a text field. Cannot be a selection list.

vb.net listview equivalent to VB6 listindex

I am trying to get the following VB6 listindex to work within my vb.net code:
setTheR CStr(payReq.ItemData(payReq.ListIndex))
But if i copy and paste that into VB.net it wont accept it.
This is what VB.net did with the converting of the VB6 to .net code:
strContract = payReq.Items.Item(payReq.FocusedItem.Index).Text
However, checking that value it returns the name instead of the index. While the VB6 code returns the value of 2311 (which is what it needs to return)
When i add items to the listview i do this:
Item = payReq.Items.Add(rsPayRequests.Fields("userid").Value)
Item.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, VB6.Format(rsPayRequests.Fields("reqdatetime").Value, "mm/dd/yyyy")))
But i noticed it does this as well:
payReq.Items.Add(New VB6.ListBoxItem(Item, rsPayRequests.Fields("requestNum").Value))
But that does not work with my listview in .net since that above is a listbox and not a listview. Is there an equivalent in .net for the listbox to have a custom index?
Any help would be great!
David
Try strContract = lstPayRequest.FocusedItem.Index
The way you are using it is returning the item at that index
Edit:
To answer your question you can add subitems to a listviewitem or you could use the tag property of the ListViewItem for your custom index.
Dim lv As New ListViewItem
lv.Text = "Item1"
lv.Tag = 1001
lv.SubItems.Add("SubItem1")
lv.SubItems.Add("SubItem2")
lstPayRequests.Items.Add(lv)
Assuming I've read this right, you're doing what many a VB6 programmer did. You're storing a relevant value in the ItemData field that isn't the index but is related to the item. Very common practice in VB6.
Unfortunately, that practice is not directly supported in VB.NET. The VB.NET list box does not have the concept of ItemData thus a direct conversion of the VB6 code is not possible. The only solution I've encountered for this is to create a class based on the ListViewItem class. It could have a display name and an item data property. Then when you add items to the list, you create your custom item class, populate the properties and add that instance to the list. Then you can retrieve the item data value by casting the selected item into your custom item class.
It's a lot of work to replicate built-in VB6 functionality but it's the only option I've seen. Hopefully someone has a better answer to this question and I'll learn too.