delphi WinForms GridView或DataSet -使用其中一个列值定位行

omqzjyyz  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(89)

试图实现一些类似于我们在 Delphi 中所拥有的东西;
1.以便能够在TDataSet中找到特定记录,您可以使用以下代码在其中找到特定行
1.在找到记录之后,它将在DBGrid上突出显示。请记住,可以在插入函数期间更新DataSet,因此所讨论的DataSet不是静态的,因此需要使用
1.任何帮助将不胜感激。
DataSet.Locate(String,Variant,[LocateOptions]);

//Delphi Example

Locate('StudentID', StudentIDVal, []); //The StudentID is a column in the DataSet & StudentIDVal is the lookup value

字符串

1mrurvl1

1mrurvl11#

感谢Jimi的回答,我能够使用下面的代码实现目标。希望它能帮助某人。

SqlDataAdapter da = new SqlDataAdapter(SelectStat, ConnString);
        DataSet ds = new DataSet();
        da.Fill(ds, "TableData");
        bsource.DataSource = ds.Tables["TableData"].DefaultView;

        GridData.AutoGenerateColumns = false;
        GridData.DataSource = bsource;

        if (ValueToFind.Trim() != "")
        {
            int i = bsource.Find("FieldToFind", ValueToFind);
            view.Rows[i].Selected = true;
            view.FirstDisplayedCell = view.SelectedRows[0].Cells[0];
        }

字符串

相关问题