Hi,
I want to search a string value in datagridview. But i don't know how i do it. please help me. I try to do it and finally wrote a code like it:
string
aa= cozellik.SelectedItem.ToString();Hi,
I want to search a string value in datagridview. But i don't know how i do it. please help me. I try to do it and finally wrote a code like it:
string
aa= cozellik.SelectedItem.ToString();
damla.yilmazer wrote:
Hi,
I want to search a string value in datagridview. But i don't know how i do it. please help me. I try to do it and finally wrote a code like it:
string
aa= cozellik.SelectedItem.ToString();if(aa == dataGridView1.Rows[0].Cells[1].Value.ToString()){MessageBox.Show("There is this record.");}else{}but this code searching in Rows[0]. I want it search in all rows at datagridview.Sorry for my bad english. I hope that i can tell my problem.
Your english is better than me!
....
foreach(DataRow row in dataGridView1.Rows)
{
if(aa == row.Cells[1].Value.ToString())
{
MessageBox.Show ...............
break;
}
}Thanks for ur reply.
but i give an error that: System.Data.DataRow does not contain a defination for 'Cells'.
with my best wishes..
foreach(DataGridViewRow row in dataGridView1.Rows)
{
// in case you want to find the value as it appears on the screen, you might want to use the
// FormattedValue property instead of Value
if (row.Cells[1].Value.ToString() == "something")
{
//
}
}
Hi,if you want to fielter in datagridview,you can also do in this way
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myView As DataView = New DataView()
myView.Table = Me.ds.Tables(0)
myView.RowFilter = "LastName='" & TextBox1.Text & "'"
DataGridView1.DataSource = myView
If myView.Count = 0 Then
MessageBox.Show("Find nothing")
Else
MessageBox.Show("Find it")
End If
End Sub
Regars.
Gavin
Already seen the problem that you mention but not resolving my problem. I tried it just see the example.
The string is removing but the messagebox is showing till the last position. Can you tell me what is the error in my code: here is my code snippets:
if (strSearch != "")
{
pTable.DefaultView.Sort = "fldID";
foreach (DataGridViewRow Row in grdData.Rows)
{
if (strSearch == Row.Cells[0].Value.ToString())
{
int row = pTable.DefaultView.Find(strSearch);
pTable.Rows.RemoveAt(row);
}
else
{
MessageBox.Show("The ID entered is wrong");}
}
}
The messageBox is showing till the last row. Can you tell me how can i resolve it.
Thanks,
Biswajit
Already seen the problem that you mention but not resolving my problem. I tried it just see the example.
The string is removing but the messagebox is showing till the last position. Can you tell me what is the error in my code: here is my code snippets:
if (strSearch != "")
{
pTable.DefaultView.Sort = "fldID";
foreach (DataGridViewRow Row in grdData.Rows)
{
if (strSearch == Row.Cells[0].Value.ToString())
{
int row = pTable.DefaultView.Find(strSearch);
pTable.Rows.RemoveAt(row);
}
else
{
MessageBox.Show("The ID entered is wrong");}
}
}
The messageBox is showing till the last row. Can you tell me how can i resolve it.
Thanks,
Biswajit
I resolve problem like this:
this is code snippet
string aa = ccompany.SelectedItem.ToString(); bool varmi= false; for (int k = 0; k < dataGridView4.Rows.Count - 1; k++) { if (aa == dataGridView4.Rows[k].Cells[0].Value.ToString()) { MessageBox.Show("there is this record"); varmi = true; break; } }
Hi,
I am being able to find and delete the string from the datagridview by the above code that i posted. But I am not getting the
correct answer at all. My problem is:
I have 500 records in myn ID column and I want to search through this item by InputDialoge.Text. If it matches with the string in the ID column then it will delete the records from the datagridview. But if it does not match with the strings of the ID column. It will prompt for message i.e. "Wrong ID Entered". But in my above code, suppose I entered a value in my InputDialogue that mathches the 5th item if the ID column of the datagridview. But when I am pressing the delete button the message box (Wrong ID Entered") is appearing for 4 times. then its deleting the string from the datagridview.
Can you tell me how can i resolve the probem. Its giving me a lots of problem.
Regards,
Biswajit