Results 1 to 8 of 8

Thread: Search Functionaltiy w/ Datagrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217

    Search Functionaltiy w/ Datagrid

    I have a search screen, which is bound to a datatable. I also have a found dialog box, and when the user puts in a value, I want to search the grid and set focus to that row if the search criteria is found. Any ideas on how 2 do this?

  2. #2
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    I'm still trying to figure out the doubleclick on the datagrid row and get my cell data back
    William E Gollnick

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I'm still trying to figure out the doubleclick on the datagrid row and get my cell data back
    Use the current property of the CurrencyManager()
    The code is in C#, but if you need me to convert it, let me know...

    Code:
    private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
    {			
        DataRowView row = (DataRowView) this.BindingContext[dataGrid1.DataSource].Current;
        MessageBox.Show(row[0].ToString());
    }

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    2 smooth...

    Code:
    private void button1_Click(object sender, System.EventArgs e)
    {
        DataView view = new DataView(ds.Tables["Orders"]);
        view.Sort = "OrderID";
        int rowIndex = view.Find(txtSearch.Text);
    			
        if(rowIndex != -1) {
            this.BindingContext[ds.Tables[0]].Position = rowIndex;	
        }
        else {
            MessageBox.Show("Record not found!");
        }						
    }

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Lethal,
    Its not the matter of how to retrive the data from the current cell. Its the problem that Datgarid DoubleClick event is not fired when you click inside a cell, cause the underlying cell gets the click, not the datagrid object. If you click on the cell bounds then its fired. So any answer to the datagrid cell doubleclick should be initialized by the cell itself.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    This might help you gollnick:
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim tb As New DataTable("testTBL")
    3.         Dim clm As New DataColumn("testCLM", GetType(String))
    4.         tb.Columns.Add(clm)
    5.         Dim tbs As New DataGridTableStyle()
    6.         Dim dgc As New dgcell()
    7.         dgc.MappingName = "testCLM"
    8.         tbs.MappingName = "testTBL"
    9.         tbs.GridColumnStyles.Add(dgc)
    10.         DataGrid1.TableStyles.Add(tbs)
    11.         DataGrid1.DataSource = tb
    12.  
    13.     End Sub
    14.  
    15.  
    16. End Class
    17. Public Class dgcell
    18.     Inherits DataGridTextBoxColumn
    19.     Public Sub New()
    20.         MyBase.New()
    21.         AddHandler Me.TextBox.DoubleClick, New System.EventHandler(AddressOf testdbclick)
    22.     End Sub
    23.     Private Sub testdbclick(ByVal sender As Object, ByVal e As System.EventArgs)
    24.         MessageBox.Show(Me.TextBox.Text)
    25.     End Sub
    26. End Class
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  7. #7
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    Thanks .. I did .. I copied in the code and tried to modify it but with no luck.. I'm a "visual" learner .. Once I see it work.. I never forget it.... This double click thing should not be this hard...
    But .. thanks again
    William E Gollnick

  8. #8
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I just started using the datagrid, someone want to take the time to explain this code?

    thanks

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim tb As New DataTable("testTBL")
    3.         Dim clm As New DataColumn("testCLM", GetType(String))
    4.         tb.Columns.Add(clm)
    5.         Dim tbs As New DataGridTableStyle()
    6.         Dim dgc As New dgcell()
    7.         dgc.MappingName = "testCLM"
    8.         tbs.MappingName = "testTBL"
    9.         tbs.GridColumnStyles.Add(dgc)
    10.         DataGrid1.TableStyles.Add(tbs)
    11.         DataGrid1.DataSource = tb
    12.  
    13.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width