0
I’m recording some data on DataGridView
and in the Event CellClick
should fill in the DateTimePicker
with the value already registered, but I’m doing something wrong.
Buttons: record, edit, delete and event cellclick
private void btnGravar_Click_1(object sender, EventArgs e)
{
i++;
dgvOS.Rows.Add(cbClientes.Text, dtpAgora.Value, dtpInicio.Value, dtpTermino.Value, txttotal.Text, cbPagamento.Text, cbStatus.Text, rtbDescricaoServico.Text);
cbClientes.SelectedIndex = -1;
dtpInicio.Text = "";
dtpTermino.Text = "";
cbStatus.SelectedIndex = -1;
cbPagamento.SelectedIndex = -1;
txttotal.Text = "0.00";
rtbDescricaoServico.Text = "";
btnEditar.Enabled = true;
btnExcluir.Enabled = true;
btnGravar.Enabled = false;
}
private void btnExcluir_Click(object sender, EventArgs e)
{
dgvOS.Rows.RemoveAt(poc);
}
private void btnEditar_Click(object sender, EventArgs e)
{
dgvOS[1, poc].Value = cbClientes.Text;
dgvOS[2, poc].Value = dtpAgora.Value;
dgvOS[3, poc].Value = dtpInicio.Value;
dgvOS[4, poc].Value = dtpTermino.Value;
dgvOS[5, poc].Value = txttotal.Text;
dgvOS[6, poc].Value = cbPagamento.Text;
dgvOS[7, poc].Value = cbStatus.Text;
dgvOS[8, poc].Value = rtbDescricaoServico.Text;
MessageBox.Show("Ordem de Serviço número: " + i + " Alterado!");
}
private void dgvOS_CellClick(object sender, DataGridViewCellEventArgs e)
{
poc = dgvOS.CurrentRow.Index; // Atualizado
cbClientes.Text = dgvOS[1, poc].Value.ToString();
dtpAgora.Value = Convert.ToDateTime(dgvOS[2, poc].Value.ToString());
dtpInicio.Value = Convert.ToDateTime(dgvOS[3, poc].Value.ToString());
dtpTermino.Value = Convert.ToDateTime(dgvOS[4, poc].Value.ToString());
txttotal.Text = dgvOS[5, poc].Value.ToString();
cbPagamento.Text = dgvOS[6, poc].Value.ToString();
cbStatus.Text = dgvOS[7, poc].Value.ToString();
rtbDescricaoServico.Text = dgvOS[8, poc].Value.ToString();
btnGravar.Enabled = false;
}
Error:
System.FormatException ocorrido
HResult=0x80131537
Message=Cadeia de caracteres não foi reconhecida como DateTime válido.
Source=mscorlib
StackTrace:
em System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
em System.Convert.ToDateTime(String value)
em ProjetoFinal.frmOrdemServico.dgvOS_CellClick(Object sender, DataGridViewCellEventArgs e) em C:\Users\willian\source\repos\ProjetoFinal\ProjetoFinal\frmOrdemServico.cs:linha 174
em System.Windows.Forms.DataGridView.OnCellClick(DataGridViewCellEventArgs e)
em System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e)
em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
em System.Windows.Forms.Control.WndProc(Message& m)
em System.Windows.Forms.DataGridView.WndProc(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.Run(Form mainForm)
em ProjetoFinal.Program.Main() em C:\Users\willian\source\repos\ProjetoFinal\ProjetoFinal\Program.cs:linha 19
Someone suggests me some change?
UPDATE
Return:
Young man, what is the return of
dgvOS[2, poc].Value
?– Jéf Bueno
I’ll show you, I’ll update
– WSS