PC Review


Reply
Thread Tools Rate Thread

Datagrid doesn't show XML data

 
 
David Fúnez
Guest
Posts: n/a
 
      29th Dec 2004
This Code Works Ok... Thanks a Lot....

Just one more question.... how do i do to Add, Edit and Delete Data in the
DataGrid.?

****** The Code ******
Imports System.Xml
Imports System.IO
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents dgLibros As System.Windows.Forms.DataGrid
Friend WithEvents btnSalvar As System.Windows.Forms.Button
Friend WithEvents btnSalir As System.Windows.Forms.Button

#Region " Código generado por el Diseñador de Windows Forms "

Dim dsLibros As New DataSet
Dim xmlFile As String = "libros.xml"
Dim xsdFile As String = "libros.xsd"
Dim path As String = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If File.Exists(path & "\" & xmlFile) Then
dsLibros.ReadXmlSchema(path & "\" & xsdFile) 'Creates all
tables and columns according to schema file.
dsLibros.ReadXml(path & "\" & xmlFile) 'Loads data, XML needs
to match XSD schema loaded before.
dgLibros.DataSource = dsLibros.Tables(0)
Else
MsgBox("no encontró el archivo")
End If
End Sub

Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSalir.Click
Me.Close()
End Sub

Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSalvar.Click
dsLibros.WriteXml(Path & "\" & xmlFile)
End Sub
End Class


--
David Fúnez
Tegucigalpa, Honduras


"David Fúnez" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This shows 0.
>
> dsLibros.ReadXml(path & "\" & xmlFile)
>
> MessageBox.Show(dsLibros.Tables(0).Rows.Count.ToString())
>
>
> --
> David Fúnez
> Tegucigalpa, Honduras
>
>
> "David Fúnez" <(E-Mail Removed)> wrote in message
> news:%23ypa$(E-Mail Removed)...
>>i mean that this code works ok in the Windows Form App i built at First,
>>this one is other project form Smart Devices.
>>
>> I'll try what tou say... thanks a lot.
>>
>> --
>> David Fúnez
>> Tegucigalpa, Honduras
>>
>>
>> ""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Do you mean this very code (with path correction) works on a desktop?
>>> Or was a similar project with, say, typed dataset?
>>>
>>> If you do this after ReadXml():
>>> MessageBox.Show(dsLibros.Tables(0).Rows.Count.ToString())
>>> Is number in a message box above zero?
>>>
>>> As to XSD file, you can load it into empty DataSet instead of creating
>>> schema programmatically (which is also fine as long as it matches XML):
>>>
>>> dsLibros = New DataSet()
>>> dsLibros.ReadXmlSchema ("FULL_PATH_TO_XSD_FILE") 'Creates all tables and
>>> columns according to schema file.
>>> dsLibros.ReadXml ("FULL_PATH_TO_XML_FILE") 'Loads data, XML needs to
>>> match
>>> XSD schema loaded before.
>>> dgLibros.DataSource = dsLibros.Tables(0) 'Show data in the grid.
>>>
>>> The benefit is what you can tweak the schema easily.
>>>
>>> Best regards,
>>>
>>> Ilya
>>>
>>> This posting is provided "AS IS" with no warranties, and confers no
>>> rights.
>>>
>>> --------------------
>>>> Reply-To: "David Fúnez" <(E-Mail Removed)>
>>>> From: "David Fúnez" <(E-Mail Removed)>
>>>> References: <(E-Mail Removed)>
>>> <(E-Mail Removed)>
>>> <(E-Mail Removed)>
>>>> Subject: Re: Datagrid doesn't show XML data
>>>> Date: Tue, 28 Dec 2004 16:47:21 -0600
>>>> Lines: 141
>>>> Organization: Income
>>>> X-Priority: 3
>>>> X-MSMail-Priority: Normal
>>>> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
>>>> X-RFC2646: Format=Flowed; Original
>>>> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
>>>> Message-ID: <(E-Mail Removed)>
>>>> Newsgroups: microsoft.public.dotnet.framework.compactframework
>>>> NNTP-Posting-Host: 205-240-200-123.reverse.cablecolor.hn
>>>> 205.240.200.123
>>>> Path:
>>> cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15
>>> phx.gbl
>>>> Xref: cpmsftngxa10.phx.gbl
>>> microsoft.public.dotnet.framework.compactframework:67663
>>>> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>>>>
>>>> Yes, the Xml file has data, but i have no created a Xsd file. ¿do i
>>>> need
>>>> it?.
>>>>
>>>> First i tried in desktop mode, and works very well.
>>>>
>>>> Thanks on advance.
>>>>
>>>> --
>>>> David Fúnez
>>>> Tegucigalpa, Honduras
>>>>
>>>>
>>>> ""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>> > Do you have any data in the XML? If you do, it has to match your
>>>> > schema.
>>>> > Print out number of rows to see if data has been loaded.
>>>> > It's also a good idea to try it on desktop first.
>>>> >
>>>> > Best regards,
>>>> >
>>>> > Ilya
>>>> >
>>>> > This posting is provided "AS IS" with no warranties, and confers no
>>>> > rights.
>>>> > --------------------
>>>> >> Reply-To: "David Fúnez" <(E-Mail Removed)>
>>>> >> From: "David Fúnez" <(E-Mail Removed)>
>>>> >> References: <(E-Mail Removed)>
>>>> >> Subject: Re: Datagrid doesn't show XML data
>>>> >> Date: Tue, 28 Dec 2004 15:50:12 -0600
>>>> >> Lines: 87
>>>> >> Organization: Income
>>>> >> X-Priority: 3
>>>> >> X-MSMail-Priority: Normal
>>>> >> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
>>>> >> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
>>>> >> X-RFC2646: Format=Flowed; Response
>>>> >> Message-ID: <(E-Mail Removed)>
>>>> >> Newsgroups: microsoft.public.dotnet.framework.compactframework
>>>> >> NNTP-Posting-Host: 205-240-200-116.reverse.cablecolor.hn
>>> 205.240.200.116
>>>> >> Path:
>>>> >
>>> cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
>>>> > phx.gbl
>>>> >> Xref: cpmsftngxa10.phx.gbl
>>>> > microsoft.public.dotnet.framework.compactframework:67657
>>>> >> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>>>> >>
>>>> >> I tried This:
>>>> >>
>>>> >> dsLibros.ReadXml("\Program Files\iPAQ\libros.xml")
>>>> >>
>>>> >> Now it doesn't show any error, but doesn't show any data in the
>>> DataGrid.
>>>> >>
>>>> >> Any help.
>>>> >>
>>>> >> --
>>>> >> David Fúnez
>>>> >> Tegucigalpa, Honduras
>>>> >>
>>>> >>
>>>> >> "David Fúnez" <(E-Mail Removed)> wrote in message
>>>> >> news:(E-Mail Removed)...
>>>> >> >I have a little APP for an iPAQ that runs Ok but it does not show
>>>> >> >any
>>>> >> > record, the problem is with the XML File as shown.
>>>> >> >
>>>> >> > The APP is a DataGrid and two Buttons, one to save data an one to
>>> exit
>>>> > the
>>>> >> > App.
>>>> >> >
>>>> >> > So, any help will be wellcome.
>>>> >> >
>>>> >> > **** The Code *****
>>>> >> > Dim dsLibros As DataSet
>>>> >> > Dim dtPrestados As DataTable
>>>> >> > Dim xmlFile As String = "Libros.xml"
>>>> >> >
>>>> >> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e
>>>> >> > As
>>>> >> > System.EventArgs) Handles MyBase.Load
>>>> >> > dtPrestados = New DataTable("prestados")
>>>> >> > dtPrestados.Columns.Add("Id", GetType(Integer))
>>>> >> > dtPrestados.Columns.Add("Titulo", GetType(String))
>>>> >> > dtPrestados.Columns.Add("prestadosA", GetType(String))
>>>> >> > dtPrestados.Columns.Add("Fecha", GetType(Date))
>>>> >> > dtPrestados.Columns.Add("Devuelto", GetType(Boolean))
>>>> >> >
>>>> >> > With dtPrestados.Columns("id")
>>>> >> > .AutoIncrement = True
>>>> >> > .AutoIncrementSeed = 1
>>>> >> > End With
>>>> >> >
>>>> >> > dsLibros = New DataSet("Libros")
>>>> >> > dsLibros.Tables.Add(dtPrestados)
>>>> >> >
>>>> >> > dgLibros.DataSource = dsLibros.Tables(0) ' that's Ok, it
>>>> >> > shows
>>>> > the
>>>> >> > columns
>>>> >> >
>>>> >> > ******* Mi problem is here, if i use this routine:
>>>> >> >
>>>> >> > If File.Exists(xmlFile) Then
>>>> >> > dsLibros.ReadXml(xmlFile)
>>>> >> > Else
>>>> >> > MsgBox("File doesn't exists")
>>>> >> > End If
>>>> >> >
>>>> >> > ******* shows the File doesn't exists Message,
>>>> >> >
>>>> >> > ******* if i put this line: dsLibros.ReadXml(xmlFile) **** out
>>> of
>>>> > the
>>>> >> > routine like this
>>>> >> >
>>>> >> > *** dgLibros.DataSource = dsLibros.Tables(0)
>>>> >> > *** dsLibros.ReadXml(xmlFile)
>>>> >> >
>>>> >> > *** it lounches an error
>>>> >> >
>>>> >> > End Sub
>>>> >> >
>>>> >> > Private Sub btnExit_Click(ByVal sender As System.Object, ByVal
>>>> >> > e
>>> As
>>>> >> > System.EventArgs) Handles btnExit.Click
>>>> >> > Me.Close()
>>>> >> > End Sub
>>>> >> >
>>>> >> > Private Sub btnSave_Click(ByVal sender As System.Object, ByVal
>>>> >> > e
>>> As
>>>> >> > System.EventArgs) Handles btnSave.Click
>>>> >> > dsLibros.WriteXml(xmlFile)
>>>> >> > End Sub
>>>> >> >
>>>> >> >
>>>> >> > --
>>>> >> > David Fúnez
>>>> >> > Tegucigalpa, Honduras
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >>
>>>> >>
>>>> >>
>>>> >
>>>>
>>>>
>>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      29th Dec 2004
So, it did not work before because no data was loaded. Most likely, the
schema created programmatically did not match XML file.

To add, delete or edit data in the grid you should work with a data source
grid is bound to.
In this case that would be table's default DataView: DataTable.DefaultView

You can use DataView's methods to add (DataView.AddNew()), delete
(DataView.Delete(row)) or modify (DataView[row][column]) rows.

To check which row is selected in the grid, use DataGrid.CurrentRowIndex.
It will match row index in the DataView bound to a grid.
However, it might NOT match row index in a DataTable, so you should not
work with table directly.

As for UI, the common practice is to pop up a new form (or use tabbed
interface) to allow row editing.
You can use buttons/menus to add/delete rows.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
> Reply-To: "David Fúnez" <(E-Mail Removed)>
> From: "David Fúnez" <(E-Mail Removed)>
> References: <(E-Mail Removed)>

<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<#ypa$(E-Mail Removed)>
<(E-Mail Removed)>
> Subject: Code Works Fine .....
> Date: Wed, 29 Dec 2004 10:56:35 -0600
> Lines: 298
> Organization: Income
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
> X-RFC2646: Format=Flowed; Response
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
> Message-ID: <#(E-Mail Removed)>
> Newsgroups: microsoft.public.dotnet.framework.compactframework
> NNTP-Posting-Host: 205-240-200-102.reverse.cablecolor.hn 205.240.200.102
> Path:

cpmsftngxa10.phx.gbl!TK2MSFTNGXS01.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP11.phx.gbl
> Xref: cpmsftngxa10.phx.gbl

microsoft.public.dotnet.framework.compactframework:67711
> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
> This Code Works Ok... Thanks a Lot....
>
> Just one more question.... how do i do to Add, Edit and Delete Data in

the
> DataGrid.?
>
> ****** The Code ******
> Imports System.Xml
> Imports System.IO
> Imports System.Windows.Forms
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> Friend WithEvents dgLibros As System.Windows.Forms.DataGrid
> Friend WithEvents btnSalvar As System.Windows.Forms.Button
> Friend WithEvents btnSalir As System.Windows.Forms.Button
>
> #Region " Código generado por el Diseñador de Windows Forms "
>
> Dim dsLibros As New DataSet
> Dim xmlFile As String = "libros.xml"
> Dim xsdFile As String = "libros.xsd"
> Dim path As String = System.IO.Path.GetDirectoryName( _
> System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If File.Exists(path & "\" & xmlFile) Then
> dsLibros.ReadXmlSchema(path & "\" & xsdFile) 'Creates all
> tables and columns according to schema file.
> dsLibros.ReadXml(path & "\" & xmlFile) 'Loads data, XML

needs
> to match XSD schema loaded before.
> dgLibros.DataSource = dsLibros.Tables(0)
> Else
> MsgBox("no encontró el archivo")
> End If
> End Sub
>
> Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnSalir.Click
> Me.Close()
> End Sub
>
> Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnSalvar.Click
> dsLibros.WriteXml(Path & "\" & xmlFile)
> End Sub
> End Class
>
>
> --
> David Fúnez
> Tegucigalpa, Honduras
>
>
> "David Fúnez" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > This shows 0.
> >
> > dsLibros.ReadXml(path & "\" & xmlFile)
> >
> > MessageBox.Show(dsLibros.Tables(0).Rows.Count.ToString())
> >
> >
> > --
> > David Fúnez
> > Tegucigalpa, Honduras
> >
> >
> > "David Fúnez" <(E-Mail Removed)> wrote in message
> > news:%23ypa$(E-Mail Removed)...
> >>i mean that this code works ok in the Windows Form App i built at

First,
> >>this one is other project form Smart Devices.
> >>
> >> I'll try what tou say... thanks a lot.
> >>
> >> --
> >> David Fúnez
> >> Tegucigalpa, Honduras
> >>
> >>
> >> ""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>> Do you mean this very code (with path correction) works on a desktop?
> >>> Or was a similar project with, say, typed dataset?
> >>>
> >>> If you do this after ReadXml():
> >>> MessageBox.Show(dsLibros.Tables(0).Rows.Count.ToString())
> >>> Is number in a message box above zero?
> >>>
> >>> As to XSD file, you can load it into empty DataSet instead of creating
> >>> schema programmatically (which is also fine as long as it matches

XML):
> >>>
> >>> dsLibros = New DataSet()
> >>> dsLibros.ReadXmlSchema ("FULL_PATH_TO_XSD_FILE") 'Creates all tables

and
> >>> columns according to schema file.
> >>> dsLibros.ReadXml ("FULL_PATH_TO_XML_FILE") 'Loads data, XML needs to
> >>> match
> >>> XSD schema loaded before.
> >>> dgLibros.DataSource = dsLibros.Tables(0) 'Show data in the grid.
> >>>
> >>> The benefit is what you can tweak the schema easily.
> >>>
> >>> Best regards,
> >>>
> >>> Ilya
> >>>
> >>> This posting is provided "AS IS" with no warranties, and confers no
> >>> rights.
> >>>
> >>> --------------------
> >>>> Reply-To: "David Fúnez" <(E-Mail Removed)>
> >>>> From: "David Fúnez" <(E-Mail Removed)>
> >>>> References: <(E-Mail Removed)>
> >>> <(E-Mail Removed)>
> >>> <(E-Mail Removed)>
> >>>> Subject: Re: Datagrid doesn't show XML data
> >>>> Date: Tue, 28 Dec 2004 16:47:21 -0600
> >>>> Lines: 141
> >>>> Organization: Income
> >>>> X-Priority: 3
> >>>> X-MSMail-Priority: Normal
> >>>> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
> >>>> X-RFC2646: Format=Flowed; Original
> >>>> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
> >>>> Message-ID: <(E-Mail Removed)>
> >>>> Newsgroups: microsoft.public.dotnet.framework.compactframework
> >>>> NNTP-Posting-Host: 205-240-200-123.reverse.cablecolor.hn
> >>>> 205.240.200.123
> >>>> Path:
> >>>

cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15
> >>> phx.gbl
> >>>> Xref: cpmsftngxa10.phx.gbl
> >>> microsoft.public.dotnet.framework.compactframework:67663
> >>>> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
> >>>>
> >>>> Yes, the Xml file has data, but i have no created a Xsd file. ¿do i
> >>>> need
> >>>> it?.
> >>>>
> >>>> First i tried in desktop mode, and works very well.
> >>>>
> >>>> Thanks on advance.
> >>>>
> >>>> --
> >>>> David Fúnez
> >>>> Tegucigalpa, Honduras
> >>>>
> >>>>
> >>>> ""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in message
> >>>> news:(E-Mail Removed)...
> >>>> > Do you have any data in the XML? If you do, it has to match your
> >>>> > schema.
> >>>> > Print out number of rows to see if data has been loaded.
> >>>> > It's also a good idea to try it on desktop first.
> >>>> >
> >>>> > Best regards,
> >>>> >
> >>>> > Ilya
> >>>> >
> >>>> > This posting is provided "AS IS" with no warranties, and confers no
> >>>> > rights.
> >>>> > --------------------
> >>>> >> Reply-To: "David Fúnez" <(E-Mail Removed)>
> >>>> >> From: "David Fúnez" <(E-Mail Removed)>
> >>>> >> References: <(E-Mail Removed)>
> >>>> >> Subject: Re: Datagrid doesn't show XML data
> >>>> >> Date: Tue, 28 Dec 2004 15:50:12 -0600
> >>>> >> Lines: 87
> >>>> >> Organization: Income
> >>>> >> X-Priority: 3
> >>>> >> X-MSMail-Priority: Normal
> >>>> >> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
> >>>> >> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
> >>>> >> X-RFC2646: Format=Flowed; Response
> >>>> >> Message-ID: <(E-Mail Removed)>
> >>>> >> Newsgroups: microsoft.public.dotnet.framework.compactframework
> >>>> >> NNTP-Posting-Host: 205-240-200-116.reverse.cablecolor.hn
> >>> 205.240.200.116
> >>>> >> Path:
> >>>> >
> >>>

cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
> >>>> > phx.gbl
> >>>> >> Xref: cpmsftngxa10.phx.gbl
> >>>> > microsoft.public.dotnet.framework.compactframework:67657
> >>>> >> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
> >>>> >>
> >>>> >> I tried This:
> >>>> >>
> >>>> >> dsLibros.ReadXml("\Program Files\iPAQ\libros.xml")
> >>>> >>
> >>>> >> Now it doesn't show any error, but doesn't show any data in the
> >>> DataGrid.
> >>>> >>
> >>>> >> Any help.
> >>>> >>
> >>>> >> --
> >>>> >> David Fúnez
> >>>> >> Tegucigalpa, Honduras
> >>>> >>
> >>>> >>
> >>>> >> "David Fúnez" <(E-Mail Removed)> wrote in message
> >>>> >> news:(E-Mail Removed)...
> >>>> >> >I have a little APP for an iPAQ that runs Ok but it does not

show
> >>>> >> >any
> >>>> >> > record, the problem is with the XML File as shown.
> >>>> >> >
> >>>> >> > The APP is a DataGrid and two Buttons, one to save data an one

to
> >>> exit
> >>>> > the
> >>>> >> > App.
> >>>> >> >
> >>>> >> > So, any help will be wellcome.
> >>>> >> >
> >>>> >> > **** The Code *****
> >>>> >> > Dim dsLibros As DataSet
> >>>> >> > Dim dtPrestados As DataTable
> >>>> >> > Dim xmlFile As String = "Libros.xml"
> >>>> >> >
> >>>> >> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal

e
> >>>> >> > As
> >>>> >> > System.EventArgs) Handles MyBase.Load
> >>>> >> > dtPrestados = New DataTable("prestados")
> >>>> >> > dtPrestados.Columns.Add("Id", GetType(Integer))
> >>>> >> > dtPrestados.Columns.Add("Titulo", GetType(String))
> >>>> >> > dtPrestados.Columns.Add("prestadosA", GetType(String))
> >>>> >> > dtPrestados.Columns.Add("Fecha", GetType(Date))
> >>>> >> > dtPrestados.Columns.Add("Devuelto", GetType(Boolean))
> >>>> >> >
> >>>> >> > With dtPrestados.Columns("id")
> >>>> >> > .AutoIncrement = True
> >>>> >> > .AutoIncrementSeed = 1
> >>>> >> > End With
> >>>> >> >
> >>>> >> > dsLibros = New DataSet("Libros")
> >>>> >> > dsLibros.Tables.Add(dtPrestados)
> >>>> >> >
> >>>> >> > dgLibros.DataSource = dsLibros.Tables(0) ' that's Ok, it
> >>>> >> > shows
> >>>> > the
> >>>> >> > columns
> >>>> >> >
> >>>> >> > ******* Mi problem is here, if i use this routine:
> >>>> >> >
> >>>> >> > If File.Exists(xmlFile) Then
> >>>> >> > dsLibros.ReadXml(xmlFile)
> >>>> >> > Else
> >>>> >> > MsgBox("File doesn't exists")
> >>>> >> > End If
> >>>> >> >
> >>>> >> > ******* shows the File doesn't exists Message,
> >>>> >> >
> >>>> >> > ******* if i put this line: dsLibros.ReadXml(xmlFile) ****

out
> >>> of
> >>>> > the
> >>>> >> > routine like this
> >>>> >> >
> >>>> >> > *** dgLibros.DataSource = dsLibros.Tables(0)
> >>>> >> > *** dsLibros.ReadXml(xmlFile)
> >>>> >> >
> >>>> >> > *** it lounches an error
> >>>> >> >
> >>>> >> > End Sub
> >>>> >> >
> >>>> >> > Private Sub btnExit_Click(ByVal sender As System.Object,

ByVal
> >>>> >> > e
> >>> As
> >>>> >> > System.EventArgs) Handles btnExit.Click
> >>>> >> > Me.Close()
> >>>> >> > End Sub
> >>>> >> >
> >>>> >> > Private Sub btnSave_Click(ByVal sender As System.Object,

ByVal
> >>>> >> > e
> >>> As
> >>>> >> > System.EventArgs) Handles btnSave.Click
> >>>> >> > dsLibros.WriteXml(xmlFile)
> >>>> >> > End Sub
> >>>> >> >
> >>>> >> >
> >>>> >> > --
> >>>> >> > David Fúnez
> >>>> >> > Tegucigalpa, Honduras
> >>>> >> >
> >>>> >> >
> >>>> >> >
> >>>> >>
> >>>> >>
> >>>> >>
> >>>> >
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >>

> >
> >

>
>
>


 
Reply With Quote
 
David Fúnez
Guest
Posts: n/a
 
      29th Dec 2004
Ilya;

Thanks a lot for your help and patience .... i will do what you say......


--
David Fúnez
Tegucigalpa, Honduras


""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> So, it did not work before because no data was loaded. Most likely, the
> schema created programmatically did not match XML file.
>
> To add, delete or edit data in the grid you should work with a data source
> grid is bound to.
> In this case that would be table's default DataView: DataTable.DefaultView
>
> You can use DataView's methods to add (DataView.AddNew()), delete
> (DataView.Delete(row)) or modify (DataView[row][column]) rows.
>
> To check which row is selected in the grid, use DataGrid.CurrentRowIndex.
> It will match row index in the DataView bound to a grid.
> However, it might NOT match row index in a DataTable, so you should not
> work with table directly.
>
> As for UI, the common practice is to pop up a new form (or use tabbed
> interface) to allow row editing.
> You can use buttons/menus to add/delete rows.
>
> Best regards,
>
> Ilya
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> --------------------
>> Reply-To: "David Fúnez" <(E-Mail Removed)>
>> From: "David Fúnez" <(E-Mail Removed)>
>> References: <(E-Mail Removed)>

> <(E-Mail Removed)>
> <(E-Mail Removed)>
> <(E-Mail Removed)>
> <(E-Mail Removed)>
> <#ypa$(E-Mail Removed)>
> <(E-Mail Removed)>
>> Subject: Code Works Fine .....
>> Date: Wed, 29 Dec 2004 10:56:35 -0600
>> Lines: 298
>> Organization: Income
>> X-Priority: 3
>> X-MSMail-Priority: Normal
>> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
>> X-RFC2646: Format=Flowed; Response
>> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
>> Message-ID: <#(E-Mail Removed)>
>> Newsgroups: microsoft.public.dotnet.framework.compactframework
>> NNTP-Posting-Host: 205-240-200-102.reverse.cablecolor.hn 205.240.200.102
>> Path:

> cpmsftngxa10.phx.gbl!TK2MSFTNGXS01.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08
> phx.gbl!TK2MSFTNGP11.phx.gbl
>> Xref: cpmsftngxa10.phx.gbl

> microsoft.public.dotnet.framework.compactframework:67711
>> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>>
>> This Code Works Ok... Thanks a Lot....
>>
>> Just one more question.... how do i do to Add, Edit and Delete Data in

> the
>> DataGrid.?
>>
>> ****** The Code ******
>> Imports System.Xml
>> Imports System.IO
>> Imports System.Windows.Forms
>>
>> Public Class Form1
>> Inherits System.Windows.Forms.Form
>> Friend WithEvents dgLibros As System.Windows.Forms.DataGrid
>> Friend WithEvents btnSalvar As System.Windows.Forms.Button
>> Friend WithEvents btnSalir As System.Windows.Forms.Button
>>
>> #Region " Código generado por el Diseñador de Windows Forms "
>>
>> Dim dsLibros As New DataSet
>> Dim xmlFile As String = "libros.xml"
>> Dim xsdFile As String = "libros.xsd"
>> Dim path As String = System.IO.Path.GetDirectoryName( _
>> System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles MyBase.Load
>> If File.Exists(path & "\" & xmlFile) Then
>> dsLibros.ReadXmlSchema(path & "\" & xsdFile) 'Creates all
>> tables and columns according to schema file.
>> dsLibros.ReadXml(path & "\" & xmlFile) 'Loads data, XML

> needs
>> to match XSD schema loaded before.
>> dgLibros.DataSource = dsLibros.Tables(0)
>> Else
>> MsgBox("no encontró el archivo")
>> End If
>> End Sub
>>
>> Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnSalir.Click
>> Me.Close()
>> End Sub
>>
>> Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnSalvar.Click
>> dsLibros.WriteXml(Path & "\" & xmlFile)
>> End Sub
>> End Class
>>
>>
>> --
>> David Fúnez
>> Tegucigalpa, Honduras
>>
>>
>> "David Fúnez" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > This shows 0.
>> >
>> > dsLibros.ReadXml(path & "\" & xmlFile)
>> >
>> > MessageBox.Show(dsLibros.Tables(0).Rows.Count.ToString())
>> >
>> >
>> > --
>> > David Fúnez
>> > Tegucigalpa, Honduras
>> >
>> >
>> > "David Fúnez" <(E-Mail Removed)> wrote in message
>> > news:%23ypa$(E-Mail Removed)...
>> >>i mean that this code works ok in the Windows Form App i built at

> First,
>> >>this one is other project form Smart Devices.
>> >>
>> >> I'll try what tou say... thanks a lot.
>> >>
>> >> --
>> >> David Fúnez
>> >> Tegucigalpa, Honduras
>> >>
>> >>
>> >> ""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >>> Do you mean this very code (with path correction) works on a desktop?
>> >>> Or was a similar project with, say, typed dataset?
>> >>>
>> >>> If you do this after ReadXml():
>> >>> MessageBox.Show(dsLibros.Tables(0).Rows.Count.ToString())
>> >>> Is number in a message box above zero?
>> >>>
>> >>> As to XSD file, you can load it into empty DataSet instead of
>> >>> creating
>> >>> schema programmatically (which is also fine as long as it matches

> XML):
>> >>>
>> >>> dsLibros = New DataSet()
>> >>> dsLibros.ReadXmlSchema ("FULL_PATH_TO_XSD_FILE") 'Creates all tables

> and
>> >>> columns according to schema file.
>> >>> dsLibros.ReadXml ("FULL_PATH_TO_XML_FILE") 'Loads data, XML needs to
>> >>> match
>> >>> XSD schema loaded before.
>> >>> dgLibros.DataSource = dsLibros.Tables(0) 'Show data in the grid.
>> >>>
>> >>> The benefit is what you can tweak the schema easily.
>> >>>
>> >>> Best regards,
>> >>>
>> >>> Ilya
>> >>>
>> >>> This posting is provided "AS IS" with no warranties, and confers no
>> >>> rights.
>> >>>
>> >>> --------------------
>> >>>> Reply-To: "David Fúnez" <(E-Mail Removed)>
>> >>>> From: "David Fúnez" <(E-Mail Removed)>
>> >>>> References: <(E-Mail Removed)>
>> >>> <(E-Mail Removed)>
>> >>> <(E-Mail Removed)>
>> >>>> Subject: Re: Datagrid doesn't show XML data
>> >>>> Date: Tue, 28 Dec 2004 16:47:21 -0600
>> >>>> Lines: 141
>> >>>> Organization: Income
>> >>>> X-Priority: 3
>> >>>> X-MSMail-Priority: Normal
>> >>>> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
>> >>>> X-RFC2646: Format=Flowed; Original
>> >>>> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
>> >>>> Message-ID: <(E-Mail Removed)>
>> >>>> Newsgroups: microsoft.public.dotnet.framework.compactframework
>> >>>> NNTP-Posting-Host: 205-240-200-123.reverse.cablecolor.hn
>> >>>> 205.240.200.123
>> >>>> Path:
>> >>>

> cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15
>> >>> phx.gbl
>> >>>> Xref: cpmsftngxa10.phx.gbl
>> >>> microsoft.public.dotnet.framework.compactframework:67663
>> >>>> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>> >>>>
>> >>>> Yes, the Xml file has data, but i have no created a Xsd file. ¿do i
>> >>>> need
>> >>>> it?.
>> >>>>
>> >>>> First i tried in desktop mode, and works very well.
>> >>>>
>> >>>> Thanks on advance.
>> >>>>
>> >>>> --
>> >>>> David Fúnez
>> >>>> Tegucigalpa, Honduras
>> >>>>
>> >>>>
>> >>>> ""Ilya Tumanov [MS]"" <(E-Mail Removed)> wrote in
>> >>>> message
>> >>>> news:(E-Mail Removed)...
>> >>>> > Do you have any data in the XML? If you do, it has to match your
>> >>>> > schema.
>> >>>> > Print out number of rows to see if data has been loaded.
>> >>>> > It's also a good idea to try it on desktop first.
>> >>>> >
>> >>>> > Best regards,
>> >>>> >
>> >>>> > Ilya
>> >>>> >
>> >>>> > This posting is provided "AS IS" with no warranties, and confers
>> >>>> > no
>> >>>> > rights.
>> >>>> > --------------------
>> >>>> >> Reply-To: "David Fúnez" <(E-Mail Removed)>
>> >>>> >> From: "David Fúnez" <(E-Mail Removed)>
>> >>>> >> References: <(E-Mail Removed)>
>> >>>> >> Subject: Re: Datagrid doesn't show XML data
>> >>>> >> Date: Tue, 28 Dec 2004 15:50:12 -0600
>> >>>> >> Lines: 87
>> >>>> >> Organization: Income
>> >>>> >> X-Priority: 3
>> >>>> >> X-MSMail-Priority: Normal
>> >>>> >> X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
>> >>>> >> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
>> >>>> >> X-RFC2646: Format=Flowed; Response
>> >>>> >> Message-ID: <(E-Mail Removed)>
>> >>>> >> Newsgroups: microsoft.public.dotnet.framework.compactframework
>> >>>> >> NNTP-Posting-Host: 205-240-200-116.reverse.cablecolor.hn
>> >>> 205.240.200.116
>> >>>> >> Path:
>> >>>> >
>> >>>

> cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
>> >>>> > phx.gbl
>> >>>> >> Xref: cpmsftngxa10.phx.gbl
>> >>>> > microsoft.public.dotnet.framework.compactframework:67657
>> >>>> >> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>> >>>> >>
>> >>>> >> I tried This:
>> >>>> >>
>> >>>> >> dsLibros.ReadXml("\Program Files\iPAQ\libros.xml")
>> >>>> >>
>> >>>> >> Now it doesn't show any error, but doesn't show any data in the
>> >>> DataGrid.
>> >>>> >>
>> >>>> >> Any help.
>> >>>> >>
>> >>>> >> --
>> >>>> >> David Fúnez
>> >>>> >> Tegucigalpa, Honduras
>> >>>> >>
>> >>>> >>
>> >>>> >> "David Fúnez" <(E-Mail Removed)> wrote in message
>> >>>> >> news:(E-Mail Removed)...
>> >>>> >> >I have a little APP for an iPAQ that runs Ok but it does not

> show
>> >>>> >> >any
>> >>>> >> > record, the problem is with the XML File as shown.
>> >>>> >> >
>> >>>> >> > The APP is a DataGrid and two Buttons, one to save data an one

> to
>> >>> exit
>> >>>> > the
>> >>>> >> > App.
>> >>>> >> >
>> >>>> >> > So, any help will be wellcome.
>> >>>> >> >
>> >>>> >> > **** The Code *****
>> >>>> >> > Dim dsLibros As DataSet
>> >>>> >> > Dim dtPrestados As DataTable
>> >>>> >> > Dim xmlFile As String = "Libros.xml"
>> >>>> >> >
>> >>>> >> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal

> e
>> >>>> >> > As
>> >>>> >> > System.EventArgs) Handles MyBase.Load
>> >>>> >> > dtPrestados = New DataTable("prestados")
>> >>>> >> > dtPrestados.Columns.Add("Id", GetType(Integer))
>> >>>> >> > dtPrestados.Columns.Add("Titulo", GetType(String))
>> >>>> >> > dtPrestados.Columns.Add("prestadosA", GetType(String))
>> >>>> >> > dtPrestados.Columns.Add("Fecha", GetType(Date))
>> >>>> >> > dtPrestados.Columns.Add("Devuelto", GetType(Boolean))
>> >>>> >> >
>> >>>> >> > With dtPrestados.Columns("id")
>> >>>> >> > .AutoIncrement = True
>> >>>> >> > .AutoIncrementSeed = 1
>> >>>> >> > End With
>> >>>> >> >
>> >>>> >> > dsLibros = New DataSet("Libros")
>> >>>> >> > dsLibros.Tables.Add(dtPrestados)
>> >>>> >> >
>> >>>> >> > dgLibros.DataSource = dsLibros.Tables(0) ' that's Ok, it
>> >>>> >> > shows
>> >>>> > the
>> >>>> >> > columns
>> >>>> >> >
>> >>>> >> > ******* Mi problem is here, if i use this routine:
>> >>>> >> >
>> >>>> >> > If File.Exists(xmlFile) Then
>> >>>> >> > dsLibros.ReadXml(xmlFile)
>> >>>> >> > Else
>> >>>> >> > MsgBox("File doesn't exists")
>> >>>> >> > End If
>> >>>> >> >
>> >>>> >> > ******* shows the File doesn't exists Message,
>> >>>> >> >
>> >>>> >> > ******* if i put this line: dsLibros.ReadXml(xmlFile) ****

> out
>> >>> of
>> >>>> > the
>> >>>> >> > routine like this
>> >>>> >> >
>> >>>> >> > *** dgLibros.DataSource = dsLibros.Tables(0)
>> >>>> >> > *** dsLibros.ReadXml(xmlFile)
>> >>>> >> >
>> >>>> >> > *** it lounches an error
>> >>>> >> >
>> >>>> >> > End Sub
>> >>>> >> >
>> >>>> >> > Private Sub btnExit_Click(ByVal sender As System.Object,

> ByVal
>> >>>> >> > e
>> >>> As
>> >>>> >> > System.EventArgs) Handles btnExit.Click
>> >>>> >> > Me.Close()
>> >>>> >> > End Sub
>> >>>> >> >
>> >>>> >> > Private Sub btnSave_Click(ByVal sender As System.Object,

> ByVal
>> >>>> >> > e
>> >>> As
>> >>>> >> > System.EventArgs) Handles btnSave.Click
>> >>>> >> > dsLibros.WriteXml(xmlFile)
>> >>>> >> > End Sub
>> >>>> >> >
>> >>>> >> >
>> >>>> >> > --
>> >>>> >> > David Fúnez
>> >>>> >> > Tegucigalpa, Honduras
>> >>>> >> >
>> >>>> >> >
>> >>>> >> >
>> >>>> >>
>> >>>> >>
>> >>>> >>
>> >>>> >
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>
>> >>
>> >
>> >

>>
>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RightToLeft DataGrid doesn't show Negative numbers correctly Uri Dor Microsoft Dot NET Framework Forms 0 4th Mar 2004 11:06 AM
DataGrid's CurrentRowIndex doesn't show new row's index. Thomas Berg Microsoft Dot NET Framework Forms 0 9th Feb 2004 02:17 AM
show data without datagrid Mike Microsoft C# .NET 1 1st Feb 2004 12:36 PM
datagrid doesn't reflect changes in data (unless datatable) Peter Bladh Microsoft Dot NET Compact Framework 4 15th Jan 2004 08:28 PM
DataGrid Update Doesn't Show Immediately Wickwack Microsoft ASP .NET 0 22nd Jul 2003 11:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 AM.