Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need help to configure the Datagrid control to:

 

Select the entire row when clicked (not just a cell).

Set individual column widths.

Make data displayed read only.

 

I've been searching google for a few hours, and couldn't find anything, please help if you can.

Posted

1. Select entire row when clicked:

 

Private Sub grdData_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdData.MouseUp
	Dim hti As DataGrid.HitTestInfo = grdData.HitTest(e.X, e.Y)
	If hti.Type = DataGrid.HitTestType.Cell Then
		grdData.Select(hti.Row)
	End If
End Sub

 

 

Set individual column widths:

 

	Dim ts As New DataGridTableStyle
	Dim col1 As New DataGridTextBoxColumn
	col1.MappingName = "ID"
	col1.HeaderText = "ID"
	col1.Width = 0
	col1.NullText = ""
	ts.GridColumnStyles.Add(col1)

	Dim col2 As New DataGridTextBoxColumn
	col2.MappingName = "ACTUAL_TIME"
	col2.HeaderText = "Time"
	col2.Width = 40
	col2.NullText = ""
	ts.GridColumnStyles.Add(col2)

               ' Repeat for each column

               grdData.TablesStyles.Clear()
               grdData.TablesStyles.Add(ts)

 

Make data displayed read only:

 


grdData.ReadOnly = True

  • 3 months later...
Posted

1. Select entire row when clicked:

 

Private Sub grdData_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdData.MouseUp
	Dim hti As DataGrid.HitTestInfo = grdData.HitTest(e.X, e.Y)
	If hti.Type = DataGrid.HitTestType.Cell Then
		grdData.Select(hti.Row)
	End If
End Sub

 

Thank you very much for this code! I have been looking for this... (just found this thread)

 

The Kid.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...