Click here to Skip to main content
15,905,504 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: open a program in a vb project interface Pin
Dave Kreskowiak5-Jul-06 1:54
mveDave Kreskowiak5-Jul-06 1:54 
QuestionGood resource to understand and implement OOP techniques in my current application? Pin
Slow Learner4-Jul-06 14:05
Slow Learner4-Jul-06 14:05 
AnswerRe: Good resource to understand and implement OOP techniques in my current application? Pin
Dave Kreskowiak5-Jul-06 4:35
mveDave Kreskowiak5-Jul-06 4:35 
AnswerRe: Good resource to understand and implement OOP techniques in my current application? Pin
TristanJ28-Jul-06 4:52
TristanJ28-Jul-06 4:52 
Questionbindingsource -> datagridview howto add rows Pin
crash8934-Jul-06 9:26
crash8934-Jul-06 9:26 
AnswerRe: bindingsource -> datagridview howto add rows Pin
crash8935-Jul-06 8:39
crash8935-Jul-06 8:39 
GeneralRe: bindingsource -> datagridview howto add rows Pin
Keith Malwitz6-Jul-06 18:51
Keith Malwitz6-Jul-06 18:51 
QuestionNeed help with Datagrid Pin
fiaolle4-Jul-06 8:27
fiaolle4-Jul-06 8:27 
Hi Confused | :confused:
I have downloaded some code (below) from this site, converted it to VB .NET and tried it and nothing happens with the datagrid(No columns are shown). Explain what is wrong and what I have to do, please. I have also tried to Import the namespace Hamster and it didn't work. Explain what I have to do to make it work.

Fia

Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Data
Imports System.Collections


'I had to comment the namespace to correct an error, it said it coudn't find the namespace

'Namespace Hamster.Common

Public Class DataGridComboBoxColumn

Inherits DataGridColumnStyle

Private _xMargin As Integer = 2

Private _yMargin As Integer = 1

Private _comboBox As ComboBox

Private _oldValue As String = ""

Private _inEdit As Boolean = False

Private _dataTable As DataTable

Private _displayMember, _valueMember As String

Public Sub New(ByVal colName As String, ByVal dataSource As DataTable, ByVal
displayMember As String, ByVal valueMember As String, ByVal dataGrid As
DataGrid)

_comboBox = New ComboBox

_comboBox.Visible = False

_comboBox.DataSource = dataSource

_dataTable = dataSource

_comboBox.DisplayMember = displayMember

_displayMember = displayMember

_valueMember = valueMember

_comboBox.ValueMember = valueMember

_comboBox.DropDownStyle = ComboBoxStyle.DropDownList

Dim _graphicsContext As Graphics = dataGrid.CreateGraphics()

Dim _widest As Single = 0

Dim _stringSize As New SizeF(0, 0)

Dim dr As DataRow

For Each dr In dataSource.Rows

_stringSize = _graphicsContext.MeasureString(dr(displayMember).ToString(),
dataGrid.Font)

If _stringSize.Width > _widest Then
_widest = _stringSize.Width
End If

Next dr

_comboBox.DropDownWidth = CInt(Math.Ceiling(_widest))

Me.Width = _comboBox.DropDownWidth + 25 ' Add the space for the dropdown
arrow

Me.MappingName = colName

Me.HeaderText = colName

dataGrid.Controls.Add(_comboBox)

End Sub 'New

Protected Overrides Sub Abort(ByVal rowNum As Integer)
_inEdit = False
_comboBox.Hide()
End Sub 'Abort

Protected Overrides Function Commit(ByVal dataSource As CurrencyManager,
ByVal rowNum As Integer) As Boolean

If Not _inEdit Then
Return True
End If

Try

Dim _value As Object = _comboBox.SelectedValue

If NullText.Equals(_value) Then
_value = System.Convert.DBNull
End If

Me.SetColumnValueAtRow(dataSource, rowNum, _value)

Catch

Finally
_inEdit = False
_comboBox.Hide()
End Try

Return True

End Function 'Commit

Protected Overloads Overrides Sub Edit(ByVal [source] As CurrencyManager,
ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal [readOnly] As
Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)

_comboBox.Text = ""

Dim _originalBounds As Rectangle = bounds

_oldValue = _comboBox.Text

If Not cellIsVisible Then
Return
End If

bounds.Offset(_xMargin, _yMargin)

bounds.Width -= _xMargin * 2

bounds.Height -= _yMargin

_comboBox.Bounds = bounds

_comboBox.Visible = True

_comboBox.SelectedValue = GetText(GetColumnValueAtRow([source], rowNum))

If Not (instantText Is Nothing) Then
_comboBox.SelectedValue = instantText
Dim [End] As Integer = _comboBox.Text.Length
_comboBox.Select([End], 0)
Else
_comboBox.SelectAll()
End If

_inEdit = True

End Sub 'Edit

Protected Overrides Function GetMinimumHeight() As Integer

Return _comboBox.PreferredHeight + _yMargin

End Function 'GetMinimumHeight

Protected Overrides Function GetPreferredHeight(ByVal g As Graphics, ByVal
val As Object) As Integer

Return FontHeight + _yMargin

End Function 'GetPreferredHeight

Protected Overrides Function GetPreferredSize(ByVal g As Graphics, ByVal val
As Object) As Size

Dim _extents As Size = Size.Ceiling(g.MeasureString(GetText(val),
Me.DataGridTableStyle.DataGrid.Font))

_extents.Width += _xMargin * 2

_extents.Height += _yMargin

Return _extents

End Function 'GetPreferredSize

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer)

Paint(g, bounds, [source], rowNum, False)

End Sub 'Paint

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal
alignToRight As Boolean)

Dim _text As String = GetText(GetColumnValueAtRow([source], rowNum))

Dim dr As DataRow

For Each dr In _dataTable.Rows

If dr(_valueMember).ToString() = _text Then
_text = dr(_displayMember).ToString()
Exit For
End If

Next dr

PaintText(g, bounds, _text, alignToRight)

End Sub 'Paint

' Helper functions

Private Sub PaintText(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal
[text] As String, ByVal alignToRight As Boolean)

Dim _backBrush = New SolidBrush(Me.DataGridTableStyle.BackColor)

Dim _foreBrush = New SolidBrush(Me.DataGridTableStyle.ForeColor)

Dim _rect As Rectangle = bounds

Dim _rectF As RectangleF = RectangleF.op_Implicit(_rect)

Dim _format As New StringFormat

If alignToRight Then
_format.FormatFlags = StringFormatFlags.DirectionRightToLeft
End If

Select Case Me.Alignment
Case HorizontalAlignment.Left
_format.Alignment = StringAlignment.Near
Case HorizontalAlignment.Right
_format.Alignment = StringAlignment.Far
Case HorizontalAlignment.Center
_format.Alignment = StringAlignment.Center
End Select

_format.FormatFlags = StringFormatFlags.NoWrap

g.FillRectangle(_backBrush, _rect)

_rect.Offset(0, _yMargin)

_rect.Height -= _yMargin

g.DrawString([text], Me.DataGridTableStyle.DataGrid.Font, _foreBrush,
_rectF, _format)

_format.Dispose()

End Sub 'PaintText

Private Function GetText(ByVal val As Object) As String

If val Is System.DBNull.Value Then
Return Me.NullText
End If

If Not (val Is Nothing) Then
Return val.ToString()
Else
Return String.Empty
End If

End Function 'GetText

End Class 'DataGridComboBoxColumn

'End Namespace 'Hamster.Common

-------------------------------------------------------------

'Imports Hamster.Common

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Dim ts As New DataGridTableStyle

ts.MappingName = "Columns"

Dim AccessDataTypes As New DataTable

AccessDataTypes.Columns.Add(New DataColumn("Number", GetType(Integer)))

AccessDataTypes.Columns.Add(New DataColumn("Name", GetType(String)))

AccessDataTypes.Rows.Add(New Object() {3, "Numeric"})

AccessDataTypes.Rows.Add(New Object() {130, "Text"})

Dim c1 As New DataGridComboBoxColumn("Type", AccessDataTypes, "Name",
"Number", theGrid)

c1.NullText = "3"

ts.GridColumnStyles.Add(c1)

End Sub

End Class


AnswerRe: Need help with Datagrid Pin
Dave Kreskowiak5-Jul-06 4:39
mveDave Kreskowiak5-Jul-06 4:39 
QuestionRandomize and Unique Numbers Pin
NickiG4-Jul-06 5:41
NickiG4-Jul-06 5:41 
AnswerRe: Randomize and Unique Numbers Pin
TristanJ4-Jul-06 8:27
TristanJ4-Jul-06 8:27 
GeneralRe: Randomize and Unique Numbers Pin
NickiG5-Jul-06 2:23
NickiG5-Jul-06 2:23 
GeneralRe: Randomize and Unique Numbers Pin
TristanJ28-Jul-06 4:31
TristanJ28-Jul-06 4:31 
AnswerRe: Randomize and Unique Numbers Pin
Guffa4-Jul-06 11:24
Guffa4-Jul-06 11:24 
QuestionAdd Scrollbar Control to my form Pin
Wael Hawari4-Jul-06 5:10
Wael Hawari4-Jul-06 5:10 
AnswerRe: Add Scrollbar Control to my form Pin
Dave Kreskowiak5-Jul-06 5:44
mveDave Kreskowiak5-Jul-06 5:44 
GeneralRe: Add Scrollbar Control to my form Pin
Wael Hawari5-Jul-06 7:44
Wael Hawari5-Jul-06 7:44 
GeneralRe: Add Scrollbar Control to my form Pin
Wael Hawari5-Jul-06 7:45
Wael Hawari5-Jul-06 7:45 
GeneralRe: Add Scrollbar Control to my form Pin
Dave Kreskowiak5-Jul-06 8:24
mveDave Kreskowiak5-Jul-06 8:24 
GeneralRe: Add Scrollbar Control to my form Pin
Wael Hawari5-Jul-06 8:36
Wael Hawari5-Jul-06 8:36 
QuestionNeed Help : insert Row into ... [modified] Pin
elpens4-Jul-06 4:15
elpens4-Jul-06 4:15 
Questiondll Problem in vb 6.0 Pin
bony_baba4-Jul-06 4:02
bony_baba4-Jul-06 4:02 
Questiongood day to all... Pin
moodsey2114-Jul-06 3:08
moodsey2114-Jul-06 3:08 
AnswerRe: good day to all... Pin
Colin Angus Mackay4-Jul-06 12:20
Colin Angus Mackay4-Jul-06 12:20 
AnswerRe: good day to all... Pin
Mekong River4-Jul-06 15:50
Mekong River4-Jul-06 15:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.