loading xml data into Ultragrid - vb.net

I am trying to show xml data in an Ultragrid. I have tried using Ultragrid.loadfromxml and using the location of the file and i have also used a file input stream and throw that into the load xml method. any help?

For this purpose you can load an XML file with something like this
Dim dt as DataTable = new DataTable("myData")
dt.ReadXml("path_to_your_file")
ultraGrid1.DataSource = dt

The UltraGrid can bind to anything that implements IList so you will need to load the data into a list of some kind. If you need the grid to respond to changes to the collection after the initial load of the data then you would want to use an IBindingList. There are more details on what the DataSource can be set to in the online help:
http://help.infragistics.com/NetAdvantage/WinForms/Current/CLR2.0/?page=Infragistics2.Win.UltraWinGrid.v12.1~Infragistics.Win.UltraWinGrid.UltraGridBase~DataSource.html
If you XML is in a format that can be read into a DataTable then the simplest solution is to bind the UltraGrid to a DataTable after calling ReadXml to load the data into the DataTable.
If you aren't able to use a DataTable, then you could use LINQ to XML to get the data and convert it to something that the UltraGrid can bind to.

To quote the Infragistics Ultragrid Ninja, Mike Saltzman, himself:
The grid needs some sort of data source that implements either IList or IBindingList. So you would have to load your XML into an object of one of those types.
So you'll need to load your XML into some collection type that implements one of those interfaces and then set that as the data source on the grid. Take a look at this question for how to load XML from a file. Then it's as simple as ...
UltraGrid1.DataSource = myAwesomeBindingListMadeFromXML
The LoadFromXML method on the UltraGrid.DisplayLayout that it designed for loaded a previously saved off layout (i.e. display settings), not the data in the grid itself.

Related

How to Populate a List<object> in XAML?

I came to know the same thing for string using the link How to Populate a List<string> in XAML?
But need to do the same on object (say for string only)..
Use the binding context to populate the list. Set the binding target as list object and binding source as the source of data.
Look here for example. I think it answers your question.

GridView does not update DataTable

I am using a DevExpress XtraGrid/View for windows forms. The datasource of the grid is a binding source, which is connected to a dataset. My problem is, this table adapter does not update the datatable. I can insert new rows without problems, but I can't update. No error message is thrown; when I save changes, the row value just reverts. This happens for every column in the row. Here is my code for saving and then reloading data:
' Class variable
Private _invoiceDetailsAdapter As dsInvoiceDetailsTableAdapters.inv_InvoiceDetailsTableAdapter = New dsInvoiceDetailsTableAdapters.inv_InvoiceDetailsTableAdapter()
'Save Data
InvInvoiceLineBindingSource.EndEdit()
_invoiceDetailsAdapter.Update(DsInvoiceDetails.inv_InvoiceDetails)
'Load
DsInvoiceDetails.inv_InvoiceDetails.Clear()
If Me._invoiceId > 0 Then
_invoiceDetailsAdapter.Fill(DsInvoiceDetails.inv_InvoiceDetails, _invoiceId)
InvInvoiceLineBindingSource.Sort = "LineNum"
End If
I've figured out that it must be the dataset itself, because I've tried using a regular DataGridView with the dataset, to no avail. I generated the dataset through the wizard and had to add ColumnName and SourceColumn properties in the parameters for Insert & Update. The parameters for Insert & Update look identical as far as properties are concerned.
I've also tried creating new datasets, datatables, binding sources and tableadapters. I've even tried a DataAdapter but there was no difference. I have literally spent 2 weeks now looking through the properties and debugging, trying to find a cause.
Can someone please offer some advice?
The problem was DevExpress' XtraGrid functionality.
The XtraGrid does not immediately save an edit value to the linked dataset. The modified row is usually posted to the data object when focus is moved to another grid row. You can programmatically force the update by calling the UpdateCurrentRow method. In your case you should only call the CloseEditor and UpdateCurrentRow methods before updating the dataset via the DB adapter object.
So if a user only updates only one row, those changes go nowhere. Read on for a code snippet...
http://www.devexpress.com/Support/Center/Question/Details/A327

How to Access DataTable Information Filled By a Module From a Form

I have a DataSet named BillMat.xsd
When my application loads, a module fills that dataset's DataTable with the correct information.
My question is ... How can I access that DataTable's already filled information from another form?
Here's how I tried to access it on one of my forms:
Dim View As New DataView
View.Table = BillMat.Tables("dtBillHeader")
But I get the following error:
If I create a new instance of my dataset and store it in a variable, I'll be able to get rid of this error message but it will also get rid of all my data in my dataset's datatables ... Is there a way to access a DataTable's information from another form?
You need to fix it so both forms are referencing the same DataSet or DataTable object. If one is a "child" form of the other, such as a dialog, you can pass it from the parent to the child via a property. Otherwise, ideally, the same data object would be injected into both forms by some third object which created both of the forms. Short of all that, you could create a singleton or global variable, but please don't!

Get Values from Listbox for if functions

Hey guys very new here.
Have a listbox that gets account names from a specific game server using this command line
Dim apikeyinfo As APIKeyInfo = api.getApiKeyInfo()
lstbxCharacters.DataSource = apikeyinfo.Characters
this code gets all the characters in a single account by displaying it in a listbox.
Now i would like to reference a character from the lisbox but not sure how
Any method such as Listbox.Get to get the value and compare it with something else?
Thanks
you can try something like
lstbxCharacters.SelectedItem
Update
To read the data from the listbox I think there are multiple ways (Assuming that it is readable).
-> Usually listbox display strings, so it should work to read to a string variable
Dim a_string as Strin = lstbxCharacters.SelectedItem
also you may like to add a small check before, assuring that an Item is currently selected:
If lstbxCharacters.SelectedIndex < 0 then return
This jumps out of current sub if no item is selected
And finally, to read the first entry, you can also do it this way:
a_string = lstbxCharacters.Items(0)
if it returns objects, then instead of accessing the object directly, it may work to do
a_string = lstbxCharacters.Items(0).ToString
(most objects allow a .ToString() Function )
Here two ideas for different solutions:
As a user commented, you could access the DataSource directly + the information which listIndex was selected. But if you do so, then maybe it is more easy (if you need to access it anyways, to go with solution 2)
Create a variable of type list(Of some_object) and fill it with the data from the datasource. It will take some time to do this, but if you define for the class some_object a function ToString, then you can fill all objects directly to the lstbxCharacters, and access them without any worries, by doing CType(lstbxCharacters.SelectedItem, some_object)
Update 2
If with reference you mean to access further information from the datasource, then you need to build some kind of query, or set the content of the listbox in relation to another control that shows the database content (in that way the listbox lstbxCharacters would act like a filter)

How do I bind a text box to a structure element?

I would like to bind the text field of a textbox to an element in an instance of a structure that I've created in a class module. When I try to create a Data Source using an OBJECT type, all I see in the tree is the name of the structure, not the instance I've created. If I select the structure anyway, the Data Sources tree does show the name of the structure and the element I'm interested in. How do I bind to a specific instance? I'm using VB.net
you have to assign instance programmatically to datasource , it will not available in design time, you can do it in formload or any other event.
something like..
BindingSource.Datasource = new instance //assign to your instance to binding source
then..
TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", BindingSource, "Name", True))// here name propery is binding to textbox