如何使用Windows应用程序C#中的文本框查找记录到datagridview。后端SQL server2005。 [英] How to find the Records into datagridview using from Textbox in windows application C#. Back End SQL server2005.

查看:52
本文介绍了如何使用Windows应用程序C#中的文本框查找记录到datagridview。后端SQL server2005。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家



如何使用Windows应用程序C#中的文本框查找记录到datagridview。后端SQL server2005。



我在数据库中有5个字段(日期,名称,地址等)。所有这些字段都与Form1中的数据网格绑定,还有一个文本框。当我加载Form1时,所有字段都显示在datagrid视图中。到目前为止一切顺利。

现在,我想在文本框中键入一些文本(private void txtdate_TextChanged(object sender,EventArgs e)),如类型日期(例如:05-05-2014),日期将在数据网格视图中突出显示它所放置的每一个。



预先感谢



Sreeni

Dear Experts

How to find the Records into datagridview using from Textbox in windows application C#. Back End SQL server2005.

I am having 5 fields(Date,Name,Address,etc..) in database. All that fields are binding with data grid in Form1 and also one text box. when i am load the Form1 all fields are displaying in datagrid view. everything going good so far.
Now, I want type the some text into textbox( private void txtdate_TextChanged(object sender, EventArgs e) ) like type date (ex:05-05-2014), the date will be highlighting in Data Grid view where every it has placed.

Thanks in Advance

Sreeni

推荐答案

有很多方法可以做到这一点。希望这会有所帮助。



There are many ways of doing it. Hope this helps.

private void txtdate_TextChanged(object sender, EventArgs e)
{
   foreach (DataGridViewRow dgr in this.dataGridView1.Rows)
   {
         foreach (DataGridViewCell cell in dgr.Cells)
                {
                    cell.Selected = false;
                    if (cell.Value != null)
                    {
                        if (cell.ValueType == typeof(DateTime))
                        {
                            if (txtDate.Text == ((DateTime)cell.Value).ToString("dd/MM/yyyy"))
                            {
                                cell.Selected = true;
                            }
                        }
                        else
                        {
                            if (txtDate.Text == cell.Value.ToString())
                            {
                                cell.Selected = true;
                            }
                        }
                    }
                }
        }
}


这篇关于如何使用Windows应用程序C#中的文本框查找记录到datagridview。后端SQL server2005。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆