Hi Afifeen,
Please update your code as below.
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.SqlClient;
namespace Company_Accounts
{
public partial class FrmUserSelection : Form
{
DataSet ds = null;
public FrmUserSelection()
{
InitializeComponent();
}
private void FrmUserSelection_Load(object sender, EventArgs e)
{
fillgrid();
ControlBox = false;
usdgv.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
txtwildsearch.Focus();
}
private void fillgrid()
{
ds=new DataSet();
ConnectionString.cnn.Open();
SqlDataAdapter da = new SqlDataAdapter("select username as [User Name],Password,Title, userrole,logincomputer as [Login Computer] ,logindate as [Login Date] ,Logintime as [Login Time] from login", ConnectionString.cnn);
da.Fill(ds, "tbl_login");
usdgv.DataSource = ds.Tables["tbl_login"];
ConnectionString.cnn.Close();
}
private void usdgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
FrmUser.dr = usdgv.CurrentRow;
fillgrid();
this.Close();
}
private void btnwildsearch_Click(object sender, EventArgs e)
{
FrmUser.dr = usdgv.CurrentRow;
this.Close();
}
private void usdgv_CellClick(object sender, DataGridViewCellEventArgs e)
{
label1.Text ="" +usdgv.Columns[usdgv.CurrentCell.ColumnIndex].HeaderText + " ";
s1.Text = "" + usdgv.Columns[usdgv.CurrentCell.ColumnIndex].HeaderText + " ";
s2.Text = "" + usdgv.Columns[usdgv.CurrentCell.ColumnIndex].HeaderText + " ";
s3.Text = "" + usdgv.Columns[usdgv.CurrentCell.ColumnIndex].HeaderText + " ";
}
private void txtwildsearch_TextChanged(object sender, EventArgs e)
{
DataView dt = ds.Tables[0].DefaultView;
string tbcolumn;
try
{
tbcolumn = usdgv.Columns[usdgv.CurrentCell.ColumnIndex].HeaderText.ToString();
dt.RowFilter = string.Format("" + tbcolumn + " ='{0}'", txtwildsearch.Text);
if (dt.Count > 0)
{
usdgv.DataSource = dt;
}
else
{
usdgv.DataSource = 0;
}
if (usdgv.RowCount == 0)
{
usdgv.DataSource = ds.Tables[0].DefaultView;
}
}
catch (Exception)
{
}
}
}
}
Hope this will help you.