So the data grids I've been working with are inherited from System.Windows.Forms.DataGrid. The problem I had was when a user double clicks between a column on the header to auto-fit the width of the column based on the data. Inside the inherited control you need something like:
Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
If e.Button = MouseButtons.Left And e.Clicks > 1 And (Me.HitTest(e.X, e.Y).Type = DataGrid.HitTestType.ColumnResize) Then
Return 'Prevent sorting on the column if it's a resize
End If
End Sub
Then in the form's double click event I put something like:
Dim CursorPosition As System.Drawing.Point = dgr.PointToClient(Cursor.Position)
Dim DataGridHitTestInfo As DataGrid.HitTestInfo = dgr.HitTest(CursorPosition)
If DataGridHitTestInfo.Type = DataGrid.HitTestType.ColumnResize Or DataGridHitTestInfo.Type = DataGrid.HitTestType.ColumnHeader Then
Application.DoEvents()
Select Case DataGridHitTestInfo.Column
Case 2
Me.col2.Width() = ResizeColumn(Me.col2.MappingName, Me.col2.HeaderText)
Case 3
Me.col3.Width() = ResizeColumn(Me.col3.MappingName, Me.col3.HeaderText)
Case 4
Me.col4.Width() = ResizeColumn(Me.col4.MappingName, Me.col4.HeaderText)
Case 5
Me.col5.Width() = ResizeColumn(Me.col5.MappingName, Me.col5.HeaderText)
Case 6
Me.col6.Width() = ResizeColumn(Me.col6.MappingName, Me.col6.HeaderText)
End Select
Column_WidthChanged(sender, e)
End If
And added a function like this:
Private Function ResizeColumn(ByVal columnName As String, ByVal header As String) As System.String
Dim i As Integer
Dim length As Single = 0
Dim g As System.Drawing.Graphics = Me.dgr.CreateGraphics
Dim str As System.String
Dim strLength As Single
length = System.Math.Max(g.MeasureString(header, Me.Font).Width(), length)
For i = 0 To Me.dsPCDCodes.Tables(0).Rows.Count - 1
If Not IsDBNull(Me.ds.Tables(0).Rows(i).Item(columnName)) Then
str = CType(Me.ds.Tables(0).Rows(i).Item(columnName), System.String)
strLength = g.MeasureString(str, Me.Font).Width()
length = System.Math.Max(strLength, length)
End If
Next
Return length
End Function
Interesting programming ideas, solutions, and logic that I have used to solve problems or have come across throughout my career.
About Me
- William Andrus
- Northglenn, Colorado, United States
- I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).
Showing posts with label DataSet. Show all posts
Showing posts with label DataSet. Show all posts
Thursday, March 01, 2007
Monday, September 25, 2006
MS ASP.Net Assessment Question: Comparing DataSet Tables
You are using the DataSet designer to create a DataSet. The DataSet contains two related tables. You create a table named Products. Products contains a VendorID column that is not unique. You also create a table named Vendors. Vendors contains a VendorID column that is the primary key.
You need to create a relationship between the two tables. Every value in the Product table's VendorID column must have a corresponding value in the Vendor table's VendorID column.
What should you do?
A)Drag a Relation object onto the designer. Set the parent table to Products. Set the child table to Vendors. Select VendorID as the column for both tables. Click Both Relation and Foreign Key Constraint.
B)Right-click the VendorID column on the Vendors table. Click Set Primary Key.
C)Drag a Relation object onto the designer. Set the parent table to Vendors. Set the child table to Products. Select VendorID as the column for both tables. Click Foreign Key Constraint Only.
D)Drag a Relation object onto the designer. Set the parent table to Products. Set the child table to Vendors. Select VendorID as the column for both tables. Click Foreign Key Constraint Only.
E)Drag a Relation object onto the designer. Set the parent table to Vendors. Set the child table to Products. Select VendorID as the column for both tables. Click Relation Only.
A) Product shouldn't be the parent table.
B) Won't solve the relationship problem.
C) Best answer, by setting the restraints, this could be used to enforced the relationship rules, so that it enforces rules about how updates and deletes to related tables are propagated.
D) Products shouldn't be the parent table.
E) There is no relation only contraint.
You need to create a relationship between the two tables. Every value in the Product table's VendorID column must have a corresponding value in the Vendor table's VendorID column.
What should you do?
A)Drag a Relation object onto the designer. Set the parent table to Products. Set the child table to Vendors. Select VendorID as the column for both tables. Click Both Relation and Foreign Key Constraint.
B)Right-click the VendorID column on the Vendors table. Click Set Primary Key.
C)Drag a Relation object onto the designer. Set the parent table to Vendors. Set the child table to Products. Select VendorID as the column for both tables. Click Foreign Key Constraint Only.
D)Drag a Relation object onto the designer. Set the parent table to Products. Set the child table to Vendors. Select VendorID as the column for both tables. Click Foreign Key Constraint Only.
E)Drag a Relation object onto the designer. Set the parent table to Vendors. Set the child table to Products. Select VendorID as the column for both tables. Click Relation Only.
A) Product shouldn't be the parent table.
B) Won't solve the relationship problem.
C) Best answer, by setting the restraints, this could be used to enforced the relationship rules, so that it enforces rules about how updates and deletes to related tables are propagated.
D) Products shouldn't be the parent table.
E) There is no relation only contraint.
Subscribe to:
Posts (Atom)