Click to See Complete Forum and Search --> : searching for text in datagrid in windows forms


raghavkotha
April 26th, 2003, 02:53 AM
hi,

I have to search the text in datagrid in windows forms application. I have to find the matching text and then make to select that cell which contains that text. It is just like Finding text.
I have not found proper functions to implement it. Not only that, if that cell is not in visible region, i have to scroll the datagrid to show that activated cell. All this functionality i needed in windows Forms Application, not in web forms. can any one can help me.

bye

raghavkotha
April 26th, 2003, 04:39 AM
hi,

i found how to search text in datagrid, by using binding context, we can able to get number of rows and number of columns, then we can able to search each cell. But one thing left is, how to make a particular cell be selected??

Not only that, i need how to scroll datagrid, can any one will help me

bye

giladasaf
April 27th, 2003, 06:46 AM
I think this should work (if I got your question right)



PHP:--------------------------------------------------------------------------------
private void serchGrid(object Obj ,DataGridCommandEventArgs e )
{
for (i=0;i<lastrow;i++)
{
//The following line is not so good since it opens the cell for change
//still it let you get to the right row (I dont think it will
//be hard to find the right property of datagrid that just directs
//to the wanted row/
DataGrid1.EditItemIndex=i;
for (i=j;i<lastcol;j++)
{

String strID=((TextBox) e.Item.Cells[j].Controls[0]).Text ;
}
}
}

--------------------------------------------------------------------------------


the strID is the value of the current cell - manipulate it as you like...

raghavkotha
April 27th, 2003, 10:03 PM
hi,

I saw your code. But i need to implement it by using Windows Forms. But not by using the classes of WebControls. So, i con't able to use it. Can you help me by providing the way to solve the problem by using System.Windows.Forms but not System.Web.

I have another problem of selecting cell. For this, there is select function in datagrid. But it is not working, when i try to select from another form. But i need to manipulate from another form. Can you provide me any solution?

bye

.........................................................................................................

Originally posted by giladasaf
I think this should work (if I got your question right)



PHP:--------------------------------------------------------------------------------
private void serchGrid(object Obj ,DataGridCommandEventArgs e )
{
for (i=0;i<lastrow;i++)
{
//The following line is not so good since it opens the cell for change
//still it let you get to the right row (I dont think it will
//be hard to find the right property of datagrid that just directs
//to the wanted row/
DataGrid1.EditItemIndex=i;
for (i=j;i<lastcol;j++)
{

String strID=((TextBox) e.Item.Cells[j].Controls[0]).Text ;
}
}
}

--------------------------------------------------------------------------------


the strID is the value of the current cell - manipulate it as you like...

raghavkotha
April 28th, 2003, 09:26 PM
hai,

I dont think, selecting a cell will be possible from another form. One thing we have to do is, any way the selection code should be written in the form where datagrid is present, and call that method from the second form whenever selection is required.
I think it will solve the problem to some extent.


bye