Skip to content

search.cs #1

@mrRadik

Description

@mrRadik
    int index = -1;
    bool found = false;
    private int Find(string text)
    {
        int _index;
        for (_index = 0; _index < gridAddresses.Rows.Count;_index++)
        {
            for (var j = 0; j < gridAddresses.Columns.Count; j++)
            {
                if (gridAddresses[j, _index].FormattedValue.ToString().ToLower().
                   Contains(text.ToLower().Trim()))
                {
                    found = true;
                    return _index;
                }
            }
        }
        if (found)
        {
            index = _index;
            return _index;
        }
        else return 0;
    }
    private int FindNext(string text, int _index)
    {
        if (index < 0)
        {
            _index = 0;
        }
        for (var i = _index+1; i < gridAddresses.Rows.Count; i++)
        {
            for (var j = 0; j < gridAddresses.Columns.Count; j++)
            {
                if (gridAddresses[j, i].FormattedValue.ToString().ToLower().
                   Contains(text.ToLower().Trim()))
                {
                    found = true;
                    _index = i;
                    return _index;
                }
            }
        }
        if (found)
        {
            index = _index;
            return _index;
        }
        else
        {
            index = -1;
            return index;
        }
    }
    private void buttonFind_Click(object sender, EventArgs e)
    {
        if (txtSearch.Text != "")
        {
            if (index < 0)
            {
                index = Find(txtSearch.Text);
                gridAddresses.CurrentCell = gridAddresses[0, index];
            }
            else
            {
                found = false;
                index = FindNext(txtSearch.Text, index);
                if (index < 0)
                {
                    index = Find(txtSearch.Text);
                }
                gridAddresses.CurrentCell = gridAddresses[0, index];
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions