Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the a class in my application. It has been bound to winform textbox controls. But the textbox which is bound to BookingNo property, always shows zero (0). But i want the textbox keep empty. Is there any way to do it? Here is my code snippet.

C#
public class Booking 
    {
    private int pBookingNo;
    private string pCustomerName;
    private string pAddress;

    public int BookingNo
    {
        get { return pBookingNo; }
        set
        {
            if (!value.Equals(pBookingNo))
            {
                pBookingNo = value;
            }
        }
    }

    public string CustomerName
    {
        get { return pCustomerName; }
        set
        {
            if (!value.Equals(pCustomerName))
            {
                pCustomerName = value;

            }
        }
    }

    public Booking() { }
}


    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        AddDataBindings();
    }

    private void AddDataBindings()
    {
        bsBooking.DataSource = typeof(Booking);

        txtBookingNo.DataBindings.Add("Text", bsBooking, "BookingNo", true, DataSourceUpdateMode.OnPropertyChanged, null, "G", GlobalVariables.CurrentCultureInfo);
        txtCustomerName.DataBindings.Add("Text", bsBooking, "CustomerName");

    }
}
Posted

1 solution

I got the solution-

C#
public int? BookingNo { get; set; }
 
Share this answer
 

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