Re: HOWTO: Highlight whole row in a datagrid.

J

Jim Slade

Fernando,

I guess you could use the DataGrid.Select() method. You can call it for
example from the MouseUp event when a cell is clicked.

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hitTest = dataGrid1.HitTest(pt);
if(hitTest.Type == DataGrid.HitTestType.Cell)
{
dataGrid1.CurrentCell = new
DataGridCell(hitTest.Row,hitTest.Column);
dataGrid1.Select(hitTest.Row);
}
}

Regards, Jim
 
F

[ F e r n a n d o L o p e s ]

Thanks Jim.
Works great. Like what am i think.

Fernando Lopes

Jim Slade said:
Fernando,

I guess you could use the DataGrid.Select() method. You can call it for
example from the MouseUp event when a cell is clicked.

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hitTest = dataGrid1.HitTest(pt);
if(hitTest.Type == DataGrid.HitTestType.Cell)
{
dataGrid1.CurrentCell = new
DataGridCell(hitTest.Row,hitTest.Column);
dataGrid1.Select(hitTest.Row);
}
}

Regards, Jim

"[ F e r n a n d o L o p e s ]" <[email protected]> schreef
in bericht news:[email protected]...
Hello ALL, is it possible to highlight only whole rows in a datagrid?
 
Joined
Sep 6, 2005
Messages
3
Reaction score
0
I need to be able to delete a row...

I have the following subroutine:

#Region " DataGrid MouseUp Event "

Private Sub highLightRow(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim pt = New Point(e.X, e.Y)
Dim grd As DataGrid = CType(sender, DataGrid)
Dim hit As DataGrid.HitTestInfo = grd.HitTest(pt)

If hit.Type = grd.HitTestType.Cell Then
grd.CurrentCell = New DataGridCell(hit.Row, hit.Column)
grd.Select(hit.Row)
End If
End Sub


#End Region

Now I need to get column1 , column2, column3
and assign them in the below parameters.

My question is how do I get the when I highlight the row and click on the delete button from a toolbar?


Public Sub doDelete()
' MDI Main Delete record requ3est toolbar button pressed
'if no records are displayed on the grid exist then exit
Dim ConnectionString As String = System.Configuration.ConfigurationSettings.AppSettings("FinSolMainDBConn")
Dim connfinsol As New System.Data.SqlClient.SqlConnection(ConnectionString)
Dim myCommand As New SqlCommand("stp_DelTransOverride ", connfinsol)
myCommand.CommandType = CommandType.StoredProcedure

'Add Parameters
' 1 Policy Number
myCommand.Parameters.Add("@Policy_Nbr", SqlDbType.VarChar, 7).Value =

' 2 Original Tranaction Override
myCommand.Parameters.Add("@Trans_CodeOrig", SqlDbType.VarChar, 6).Value =

' 3 Transaction Effective Date
myCommand.Parameters.Add("@Trans_Eff_Date", SqlDbType.DateTime, 8).Value =

'Open Connection
Try
'Open Connection
connfinsol.Open()
myCommand.ExecuteNonQuery()
MsgBox("Data Saved Successfully !", MsgBoxStyle.Information, Me.Text)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, Me.Text)
Finally
If myCommand.Connection.State = ConnectionState.Open Then
myCommand.Connection.Close()
End If
End Try

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top