Fórum inserir em arquivo XML #446156
21/06/2013
0
int next = contatos.Contato[contatos.Contato.Count - 1].Id + 1;
codigo completo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Xml;
namespace System.XML_Example
{
public partial class Form3 : Form
{
Contatos contatos = null;
public Form3()
{
InitializeComponent();
}
private void BindListBox() {
contatos = SContatos.Read();
listBox1.DataSource = contatos.Contato;
listBox1.DisplayMember = "Nome";
listBox1.ValueMember = "Id";
}
private void Form3_Load(object sender, EventArgs e)
{
this.BindListBox();
}
private void btnSalvar_Click(object sender, EventArgs e)
{
Contato c = new Contato();
c.Id = this.NextId();
c.Nome = txtNome.Text;
c.Telefone = txtTelefone.Text;
contatos.Contato.Add(c);
SContatos.Write(contatos);
this.BindListBox();
}
private int NextId() {
int next = contatos.Contato[contatos.Contato.Count - 1].Id + 1;
return next;
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex > -1)
{
Contato c = contatos.Contato.Find(p => p.Id == (int)listBox1.SelectedValue);
contatos.Contato.Remove(c);
SContatos.Write(contatos);
this.BindListBox();
}
else
{
MessageBox.Show("Nenhum ítem selecionado");
}
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Contato c = contatos.Contato.Find(p => p.Id == (int)listBox1.SelectedValue);
MessageBox.Show("Nome: " + c.Nome + "\n" + "Telefone: " + c.Telefone);
}
}
}
Roniere Almeida
Curtir tópico
+ 0Posts
21/06/2013
Joel Rodrigues
Gostei + 0
21/06/2013
Roniere Almeida
if you are working with a collection, make sure the index is less than the size of the collection.
Make sure the arguments to this method have valid values.
Get general help for this exception.
Gostei + 0
21/06/2013
Joel Rodrigues
Gostei + 0
21/06/2013
Roniere Almeida
Gostei + 0
21/06/2013
Joel Rodrigues
Gostei + 0
21/06/2013
Roniere Almeida
Gostei + 0
21/06/2013
Joel Rodrigues
Gostei + 0
21/06/2013
Roniere Almeida
Gostei + 0
21/06/2013
Joel Rodrigues
Gostei + 0
21/06/2013
Joel Rodrigues
Gostei + 0
23/06/2013
Roniere Almeida
Gostei + 0
23/06/2013
Aluisio Cavalcante
Gostei + 0
24/06/2013
Joel Rodrigues
Pode-se perfeitamente fazer um cadastro utilizando XML, Aluisio. Dê uma olhada nesse post de minha autoria, nele eu dou um exemplo básico de como fazer isso: [url]http://www.linhadecodigo.com.br/artigo/3449/manipulando-arquivos-xml-em-csharp.aspx[/url].
Gostei + 0
24/06/2013
Joel Rodrigues
Gostei + 0
24/06/2013
Roniere Almeida
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)