Imagine a WinGrid loaded with records and upon the end user double clicking on a Row, a Form loads with the current record along with all related Form fields for data entry. To help achieve this kind of metaphor, you can easily handle the DoubleClickRow event of the WinGrid. The event arguments present you with the actual Row that was double clicked as well as an enumeration that describes which part of the Row was double clicked (such as the Cell area, the Preview area and so forth)
Private Sub UltraGrid1_DoubleClickRow( _
ByVal sender As System.Object, _
ByVal e As DoubleClickRowEventArgs) _
Handles UltraGrid1.DoubleClickRow
Dim theCust As Customer
theCust = DirectCast(e.Row.ListObject, Customer)
Dim d As New CustDetailsForm(theCust)
d.ShowDialog()
End Sub
private void ultraGrid1_DoubleClickRow(
object sender,
DoubleClickRowEventArgs e)
{
Customer theCust = null;
theCust = e.Row.ListObject as Customer;
CustDetailsForm d = new CustDetailsForm(theCust);
d.ShowDialog();
}
This example assumes that we are bound to a collection of type Customer. If you notice, on the DoubleClick of the Row, we use the event argument e.Row.ListObject to get a reference to the actual Customer object that this Row represents. We then instantiate the Form that will be used to show the Customer Details (CustDetailsForm) and pass the Customer object into its constructor. We then use the Form’s ShowDialog method to present the Form.
The following example also shows how to further enhance the logic by checking exactly which part of the Row was double clicked. Notice that if the Cell or CellArea was double clicked, we show the Customer Details Form. If the RowSelectorArea is double clicked, then you may want to perform other logic. Either way, it is simple to implement by using the event arguments.
Private Sub UltraGrid1_DoubleClickRow( _
ByVal sender As System.Object, _
ByVal e As DoubleClickRowEventArgs) _
Handles UltraGrid1.DoubleClickRow
Select Case e.RowArea
Case RowArea.Cell, RowArea.CellArea
Dim theCust As Customer
theCust = DirectCast(e.Row.ListObject, Customer)
Dim d As New CustDetailsForm(theCust)
d.ShowDialog()
Return
Case RowSelectorArea
'do something else
Return
End Select
End Sub
private void ultraGrid1_DoubleClickRow(
object sender,
DoubleClickRowEventArgs e)
{
switch (e.RowArea)
{
case RowArea.Cell:
case RowArea.CellArea:
Customer theCust = null;
theCust = e.Row.ListObject as Customer;
CustDetailsForm d = new CustDetailsForm(theCust);
d.ShowDialog();
break;
case RowArea.RowSelectorArea:
//do something else
break;
}
}