Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to load my datagrid view from main form to child form. the child form contain textbox... this is the code when my child form load and fill the textbox wtih data from datagridview..


C#
private void Form3_Load(object sender, EventArgs e)
        {                       
            this.TopMost = true;
            txtkode.Text = Data["kodebuku"].ToString();
            txtkode1.Text = Data["kodebuku"].ToString();
            txtjudul.Text = Data["judulbuku"].ToString();
            txtpengarang.Text = Data["pengarang"].ToString();
            txtkategori.Text = Data["namakategori"].ToString();
            txtpenerbit.Text = Data["penerbit"].ToString();
            txttahun.Text = Data["tahunterbit"].ToString();
            txtstok.Text = Data["stokbuku"].ToString();
            tglter.Text = Data["tglpenerimaan"].ToString();
        }



txttahun.text is a datetimepicker, and its format is yyyy (show year only) but when it load show an error "String was not recognize as a valid Date Time". tglter.Text is also a datetimepicker but it format is short (mm/dd/yyyy). and while i load the child form (when i disable the txttahun.Text) the error is not shown.. how can this happen ? i dont understand at all..

please help me.. and thank you before
Posted

1 solution

Try using the following lines and let me know if there is any other issue:
C#
DateTime elshose;
bool elshoseOkay;
//elshoseOkay = DateTime.TryParse("1/21/2012 12:00:00 AM", out elshose);
elshoseOkay = DateTime.TryParse(Data["tahunterbit"].ToString(), out elshose);
if (elshoseOkay)
{
   txttahun.CustomFormat = "yyyy";
   txttahun.Format = DateTimePickerFormat.Custom;
   txttahun.Text = elshose.Year.ToString();
}
 
Share this answer
 
Comments
Member 8743576 28-May-12 8:27am    
it show no error, but the txttahun not load the year i input... i input 2008 on my database but when the form load it show 2012... this is my code


it show no error, but the txttahun not load the day i input.. i input 2008 but when the form load it show 2012 (current year)


this is my code

private void Form3_Load(object sender, EventArgs e)
{
DateTime elshose;
bool elshoseOkay;
elshoseOkay = DateTime.TryParse(Data["tahunterbit"].ToString(), out elshose);
if (elshoseOkay)
{
txttahun.CustomFormat = "yyyy";
txttahun.Format = DateTimePickerFormat.Custom;
txttahun.Text = elshose.Year.ToString();
}
this.TopMost = true;
txtkode.Text = Data["kodebuku"].ToString();
txtkode1.Text = Data["kodebuku"].ToString();
txtjudul.Text = Data["judulbuku"].ToString();
txtpengarang.Text = Data["pengarang"].ToString();
txtkategori.Text = Data["namakategori"].ToString();
txtpenerbit.Text = Data["penerbit"].ToString();
//txttahun.Text = Data["tahunterbit"].ToString();
txtstok.Text = Data["stokbuku"].ToString();
tglter.Text = Data["tglpenerimaan"].ToString();
}
Monjurul Habib 28-May-12 17:22pm    
please debug and let me know the value of "Data["tahunterbit"].ToString()".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900