TextBox中搜索值,因此它发现它在位于GridView中数据 [英] Search value in textBox so it finds it in the data located in gridView
本文介绍了TextBox中搜索值,因此它发现它在位于GridView中数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有curently我正在打开一个.xls文件,通过在文本框中输入该文件的位置,我想通过在文本框中输入它来搜索某个值,并删除其中的价值所在的行。
Curently i am opening a .xls file, by entering the file location in a text box and i want to search a certain value by entering it in a text box and delete the row in which the value resides in.
下面是code为Form1,包含在DataGridView:
Here is the code for Form1, that contains the dataGridView:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Plan_de_lucru_1._0
{
public partial class frPlanMain : Form
{
public frPlanMain()
{
InitializeComponent();
}
private void frPlanMain_Load(object sender, EventArgs e)
{
}
private void GoButton_Click(object sender, EventArgs e)
{
string constr = "Provider = MicroSoft.Jet.OLEDB.4.0; Data Source=" + locTBox.Text + "; Extended Properties =\"Excel 8.0; HDR=Yes;\";";
OleDbConnection con = new OleDbConnection(constr);
OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [" + shTBox.Text + "$]", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dGVPlan.DataSource = dt;
new SearchWindow().Show();
this.Show();
}
}
}
这是窗体2包含在其中,我想进入搜索价值的文本框和按钮。
This is Form2 that contains the textBox and button in which i want to enter the search value.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Plan_de_lucru_1._0
{
public partial class SearchWindow : Form
{
public SearchWindow()
{
InitializeComponent();
}
private void SearchButtonW_Click(object sender, EventArgs e)
{
String str = "select * from searchBox where ( Name like '%' + @search + '%')";
BindingSource bs = new BindingSource();
}
}
}
感谢您的帮助。
推荐答案
这为我工作:
namespace Plan_de_lucru_1._0
{
public partial class SearchWindow : Form
{
public frPlanMain refTofrPlanMain;
public SearchWindow(frPlanMain f) //<<Edit made here
{
refTofrPlanMain = f;
InitializeComponent();
}
private void SearchButtonW_Click(object sender, EventArgs e)
{
{
(refTofrPlanMain.dGVPlan.DataSource as DataTable).DefaultView.RowFilter = string.Format("Vodic = '{0}'", searchTBoxW.Text);
foreach (DataGridViewRow item in refTofrPlanMain.dGVPlan.Rows)
{
if (item.Visible)
{
item.Selected = true;
break;
这篇关于TextBox中搜索值,因此它发现它在位于GridView中数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文