Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter a datagrid which is filled with XML data 2

Status
Not open for further replies.

ErnstJan

Programmer
Nov 10, 2002
114
NL
Oke,

I am a newbie to VB.net so be kind to me.
I'm trying to create a program that can work without any database backend.

So i created a xml-file throug Access 2003 containing the data.
I can fill a datagrid on a form use the following code
Code:
        Dim ds As New DataSet

        ds.ReadXml("..\Spareparts.xml")
        dgSpareParts.SetDataBinding(ds, "Qry_Overzicht_Spare_Parts")

Now i want to do a couple of things which a can't figure out
1) be able to set a default column width for the different colums (i figured out how to do this with a table from a SQL-server but not with the XML data)
2) be able to filter the data in the datagrid. (Also know how to do this with SQL-table)

Can someone please give me example code, links or advice to solve this

Thx in advance
 
Code:
ds.ReadXml("..\Spareparts.xml")
dim dv as dataview = ds.tables("tablename").defaultview
dv.filter = "FieldName = '" & value & "'"
dv.sort = "FieldName ASC"

dgSpareParts.SetDataBinding(dv, "Qry_Overzicht_Spare_Parts")

I'm not a big fan of binding. Heck, I don't even like the data view. I just had to beat on one earlier today. Column widths you'll probrably have to set through ColumnStyles, I know it's been covered here at some point in time.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
ThatRickGuy,

Thanks for the reply but i get the same result.
Somehow it won't filter the data.
Program didn't understand 'Filter' (line 3) changed that to 'rowfilter' because that option was avialable.

But let me ask something else because i am still learning.

How would you make a form where people can search a database?
This program must be able to run stand alone. If possible of a CD/DVD.

I am not asking for a program but only for direction and possible some code how to make it work

Ernst Jan
 

if found the filter problem.

Last line should be like this
Code:
dgSpareParts.DataSource = dv

Still can set the column width. Still working on that.

I am open for suggestions how to do it in an other way.

Ernst Jan
 
Me personally, I don't like data binding and I hate data views. I would do it in one of a few ways:

On a fast network (like an office LAN) with a good database server, I would let the server do the work. Using either Stored Procedures or dynamic SQL to query the data needed to find what the user is looking for.

On a slow network, or with a slow database server (like a distributed app that calls back to a web server for data) I would pull down the data set once. Then I would use the datatable.Select("field=value") method to get an array of data rows. Once I have the data rows I would loop through them and add them to a flex grid or what ever control I was working with. It takes more work this way, but it gives you more control over the data, and it's significantly faster then using a dataview.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
ThatRickyGuy,

Do you have some example code for me how to use Datatable.select("field=value") methode. And how to display it. If it is possible for you.
The application i am trying to create is without a database server or internet connection
That why i tried an XML document as dataprovider.

Thanks in advance

Ernst Jan
 
Sorry for the late reaction but i appreciate the information you guys have given me.
Both have a star from me for the info

Thanks again

Ernst Jan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top