1
How can I do this, see what I have so far:
Datagrid, I need to load the comboBox
and the valor unitário
with values I previously saved on a txt
Button save products, save name - price
private void btnGravar_Click(object sender, EventArgs e)
{
i++;
double vtotal = 0;
vtotal = Convert.ToDouble(txtVlrVenda.Text) * Convert.ToInt32(txtQntd.Text);
dgvProdutos.Rows.Add(i, txtNome.Text, txtFornecedor.Text, maskCNPJ.Text, txtEnd.Text, txtCidade.Text, txtUF.Text, maskFone.Text, txtEmail.Text, txtNfe.Text, txtVlrVenda.Text, txtQntd.Text, vtotal);
using (StreamWriter writer = new StreamWriter(@"C:\\Users\\willian\\Downloads\\dbProdutos.txt", true))
{
writer.WriteLine(txtNome.Text + " - " + txtVlrVenda.Text);
}
txtNome.Text = "";
txtFornecedor.Text = "";
maskCNPJ.Text = "";
txtEnd.Text = "";
txtCidade.Text = "";
txtUF.Text = "";
maskFone.Text = "";
txtEmail.Text = "";
txtNfe.Text = "";
txtVlrVenda.Text = "";
txtQntd.Text = "";
btnEditar.Enabled = true;
btnExcluir.Enabled = true;
btnGravar.Enabled = false;
}
In this previous topic: Save to txt and recover in a combobox taught me to carry comboBox
, however in this case I did not understand how to access the column I created inside Datagrid. The code so far is like this:
private void frmOrdemServico_Load(object sender, EventArgs e)
{
string[] lineOfContents = File.ReadAllLines(@"C:\\Users\\willian\\Downloads\\dbClientes.txt");
cbClientes.Items.Clear(); // limpar para não duplicar valores
foreach (var line in lineOfContents)
{
string[] nomes = line.Split(',');
cbClientes.Items.Add(nomes[0]);
}
string[] Produtos = File.ReadAllLines(@"C:\\Users\\willian\\Downloads\\dbProdutos.txt");
foreach (var line in Produtos)
{
string[] produtos = line.Split('-');
dgvProdutos. //comboBox que irá carregar os produtos
dgvProdutos. //txtBox que irá mostrar o valor de cada produto seleciona, ja cadastrado no txt
}
}
Can anyone help me with something? I even found this site that teaches to recover values that are concatenated but to put in Datagrid does not say anything: Writing and Reading Data in Text File with Csharp
Question: why are you using a TXT for such complex operations?
– Jéf Bueno
Answer: Because I was using a database and I couldn’t, so it seems more viable this way
txt
, since I will only present to teachers and the subjects does not charge database at most using same text files. I just want to show there and good will not record anything else, just to show how the system works stream passes etc.– WSS