views:

10

answers:

0

I am creating a C# based windows form application.

I have a dataview and I have binded various labels to this dataview. The problem is that all the text in the label comes directly through the binding. However I need to format the data before displaying it.

I need to display the text in RED if the label value is >0 and the text in GREEN if the label value is <0.

Please help.

heres the code:

private void FormSales_Load(object sender, EventArgs e)
{
    comboBox1.SelectedIndex = 0;

    DateTime date = DateTime.Now;
    label19.Text = date.ToString();
    dataGridView2.ReadOnly = true;
    dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
    dataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView2.StandardTab = true;

    // USING DATASET
    dsCustomers = Main.GetDbUpperLayerAdapter().SelectAllCustomerDetails();

    dv = new DataView(dsCustomers.Tables[0]);
    label9.DataBindings.Add("text", dv, "code");
    label25.DataBindings.Add("text", dv, "tempbal");
    label29.DataBindings.Add("text", dv, "title");
    label30.DataBindings.Add("text", dv, "address");
    label31.DataBindings.Add("text", dv, "phone");

    label9.Visible = false;
    label25.Visible = false;
    label29.Visible = false;
    label30.Visible = false;
    label31.Visible = false;

}


private void textBox5_TextChanged(object sender, EventArgs e)
{

    string qText = textBox5.Text;
    if (qText == "")
    {
        label9.Visible = false;
        label25.Visible = false;
        label29.Visible = false;
        label30.Visible = false;
        label31.Visible = false;
        dataGridView2.DataSource = null;
    }
    else
    {
        label9.Visible = true;
        label25.Visible = true;
        label29.Visible = true;
        label30.Visible = true;
        label31.Visible = true;

        dv.RowFilter = "Convert(code, 'System.String') like '" + qText +
            "%' OR Convert(title, 'System.String') like '%" + qText +
            "%' OR Convert(address, 'System.String') like '%" + qText +
            "%' OR Convert(email, 'System.String') like '" + qText +
            "%' OR Convert(phone, 'System.String') like '" + qText +
            "%' OR Convert(family, 'System.String') like '%" + qText + "%'";

        dataGridView2.DataSource = dv;
        dataGridView2.Refresh();
    }
}