Search code examples
c#-4.0bindingsource

searching in List<>


i want to find value in List<> but i am not getting the integer value. Here is my code from that i want to find the value in the List

private void txtnapsaserach_TextChanged(object sender, EventArgs e)
{
    try
    {
       //decimal find = decimal.Parse(txtnapsaserach.Text);

       if (decimal.Parse(txtnapsaserach.Text) > 0)
       {
       List<NapsaTable> _napsatabs = this.napsaTableBindingSource.List as List<NapsaTable>;
       this.napsaTableBindingSource.DataSource = 
        _napsatabs.Where(p =>p.NapsaRate.Equals(txtnapsaserach.Text)).ToList();

       }
    }
    catch (Exception Ex)
    {
    }
}

any solution for me . Because this works for me when i try to find string value.


Solution

  • private void txtnapsaserach_TextChanged(object sender, EventArgs e)
    {
         float value;
         if (!float.TryParse(txtnapsaserach.Text, out value))
             return; // return if text cannot be parsed as float number
    
         if (value > 0)
         {
            var napsatabs = napsaTableBindingSource.List as List<NapsaTable>;
            napsaTableBindingSource.DataSource = 
                napsatabs.Where(p =>p.NapsaRate == value).ToList();
         }
    }
    

    try this