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?
Printable View
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?
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()Quote:
I'm still trying to figure out the doubleclick on the datagrid row and get my cell data back
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());
}
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!");
}
}
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.
This might help you gollnick:
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim tb As New DataTable("testTBL") Dim clm As New DataColumn("testCLM", GetType(String)) tb.Columns.Add(clm) Dim tbs As New DataGridTableStyle() Dim dgc As New dgcell() dgc.MappingName = "testCLM" tbs.MappingName = "testTBL" tbs.GridColumnStyles.Add(dgc) DataGrid1.TableStyles.Add(tbs) DataGrid1.DataSource = tb End Sub End Class Public Class dgcell Inherits DataGridTextBoxColumn Public Sub New() MyBase.New() AddHandler Me.TextBox.DoubleClick, New System.EventHandler(AddressOf testdbclick) End Sub Private Sub testdbclick(ByVal sender As Object, ByVal e As System.EventArgs) MessageBox.Show(Me.TextBox.Text) End Sub End Class
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
I just started using the datagrid, someone want to take the time to explain this code?
thanks
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim tb As New DataTable("testTBL") Dim clm As New DataColumn("testCLM", GetType(String)) tb.Columns.Add(clm) Dim tbs As New DataGridTableStyle() Dim dgc As New dgcell() dgc.MappingName = "testCLM" tbs.MappingName = "testTBL" tbs.GridColumnStyles.Add(dgc) DataGrid1.TableStyles.Add(tbs) DataGrid1.DataSource = tb End Sub