Click here to Skip to main content
15,917,005 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Hooking the Mouse Pin
AndrewVos16-Jul-06 19:17
AndrewVos16-Jul-06 19:17 
QuestionSaving user inputs for later use Pin
Almerica15-Jul-06 1:49
Almerica15-Jul-06 1:49 
AnswerRe: Saving user inputs for later use Pin
Ed.Poore15-Jul-06 13:19
Ed.Poore15-Jul-06 13:19 
AnswerRe: Saving user inputs for later use Pin
Werries17-Jul-06 9:14
Werries17-Jul-06 9:14 
QuestionWhat is an XML editor? Pin
szevy_suez15-Jul-06 0:50
szevy_suez15-Jul-06 0:50 
AnswerRe: What is an XML editor? [modified] Pin
giddy_guitarist15-Jul-06 8:02
giddy_guitarist15-Jul-06 8:02 
AnswerRe: What is an XML editor? Pin
giddy_guitarist15-Jul-06 20:59
giddy_guitarist15-Jul-06 20:59 
QuestionTrouble with combobox in DataGrid Pin
fiaolle14-Jul-06 23:29
fiaolle14-Jul-06 23:29 
Hi The first set of source code is the class for a combobox in a grid,
hopefully. In the second set of code we try to use the combobox class, but
the grid is empty.
I don't understand how this works. The first set of code I downloaded from
internet and when i tried it, it worked fine. But when I changed the second
part of the code it started to give me trouble. Before I changed the code
they used Datacolumns,Datarows and Datatables and added them to the Dataset
which they used to the Datagrid and it worked fine. I don't understand what
is wrong know that I'm using a table I haven't "made" myself but a table I
got from a connection. As the third set of code showing, when using
comboboxes you can set the Datasource to a table you have connected to with
a connection and it works fine, so I think the second part of code should
work, but the grid is empty when the program starts.

If there is anyone who understand my problem and have a solution, please
give me an answer.

Thanks

Fia


'The MyComboColumn class
Imports System.Data
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Namespace ComboBoxTest
Public Class MyComboColumn
Inherits System.Windows.Forms.DataGridTextBoxColumn
Private _cboColumn As ComboBox
Private _objSource As Object
Private _strMember As String
Private _strValue As String
Private _bIsComboBound As Boolean = False
Private _backBrush As Brush = Nothing
Private _foreBrush As Brush = Nothing
Private _iRowNum As Integer
Private _cmSource As CurrencyManager
Public Sub New(ByVal objSource As DataSet, ByVal strMember As String, ByVal
strValue As String, ByVal bUseDropDownList As Boolean)
'_objSource = objSource
_strMember = strMember
_strValue = strValue
_cboColumn = New ComboBox
_cboColumn.DataSource = objSource.Tables(0)
_cboColumn.DisplayMember = _strMember
_cboColumn.ValueMember = _strValue
If bUseDropDownList = True Then
_cboColumn.DropDownStyle = ComboBoxStyle.DropDownList
Me.ReadOnly = True
Else
'AddHandler _cboColumn.KeyPress, AddressOf _cboColumn_KeyPress
AddHandler _cboColumn.KeyUp, AddressOf _cboColumn_KeyUp
End If
AddHandler _cboColumn.Leave, AddressOf cboColumn_Leave
_cboColumn.Visible = False
End Sub
Private Sub _cboColumn_KeyPress(ByVal sender As Object, ByVal e As
KeyPressEventArgs)
e.Handled = True
End Sub
Private Shadows Sub _cboColumn_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
Dim index As Integer
Dim actual As String
Dim found As String
' Do nothing for certain keys such as navigation keys
If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.ShiftKey) Or _
(e.KeyCode = Keys.End)) Then
Return
End If
' Store the actual text that has been typed
actual = _cboColumn.Text
' Find the first match for the typed value
index = _cboColumn.FindString(actual)
' Get the text of the first match
If (index > -1) Then
found = _cboColumn.Items(index).ToString()
' Select this item from the list
_cboColumn.SelectedIndex = index
' Select the portion of the text that was automatically
' added so further typing will replace it
_cboColumn.SelectionStart = actual.Length
_cboColumn.SelectionLength = found.Length
End If
End Sub
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)
If _bIsComboBound = False Then
_bIsComboBound = True
Me.DataGridTableStyle.DataGrid.Controls.Add(_cboColumn)
End If
_iRowNum = rowNum
_cmSource = source
_cboColumn.Font = Me.TextBox.Font
Dim anObj As Object = Me.GetColumnValueAtRow(source, rowNum)
_cboColumn.Bounds = bounds
_cboColumn.BeginUpdate()
_cboColumn.Visible = True
If Not (anObj.GetType Is System.DBNull.Value) Then
'TextObject Is System.DBNull.Value
_cboColumn.SelectedValue = anObj
Else
_cboColumn.SelectedIndex = 0
End If
_cboColumn.EndUpdate()
_cboColumn.Focus()
End Sub
Public Sub cboColumn_Leave(ByVal sender As Object, ByVal e As EventArgs)
Dim objValue As Object = _cboColumn.SelectedValue
If objValue Is Nothing Then
objValue = DBNull.Value
Else
Me.SetColumnValueAtRow(_cmSource, _iRowNum, objValue)
End If
_cboColumn.Visible = False
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim strCountry As String = "Huh?"
Dim aRowA As DataRow()
Dim anObj As Object = Me.GetColumnValueAtRow(source, rowNum)
Dim aType As Type = anObj.GetType
If Not (aType.GetType Is System.DBNull.Value) Then
aRowA = CType(_objSource, DataTable).Select(_strValue + " = " +
anObj.ToString)
Else
aRowA = CType(_objSource, DataTable).Select
End If
If aRowA.Length > 0 Then
strCountry = aRowA(0)(_strMember).ToString
End If
Dim rect As Rectangle = bounds
Dim rectF As RectangleF = rectF.op_Implicit(rect) ' Convert to
If Me._backBrush Is Nothing Then
g.FillRectangle(backBrush, rect)
Else
g.FillRectangle(_backBrush, rect)
End If
rect.Y += 2
If Me._foreBrush Is Nothing Then
'g.DrawString(Text, Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF,
Format)
g.DrawString(strCountry, Me.TextBox.Font, foreBrush, rectF)
Else
g.DrawString(strCountry, Me.TextBox.Font, _foreBrush, rectF)
End If
End Sub
Public WriteOnly Property backgroundColour() As System.Drawing.Color
Set(ByVal Value As System.Drawing.Color)
If Value.Equals(System.Drawing.Color.Transparent) Then
Me._backBrush = Nothing
Else
Me._backBrush = New SolidBrush(Value)
End If
End Set
End Property
Public WriteOnly Property foregroundColour() As System.Drawing.Color
Set(ByVal Value As System.Drawing.Color)
If Value.Equals(System.Drawing.Color.Transparent) Then
Me._foreBrush = Nothing
Else
Me._foreBrush = New SolidBrush(Value)
End If
End Set
End Property
End Class
End Namespace

----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------
'The Form's class
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports ReceptNet.ComboBoxTest
Public Class DataGridSample
Inherits Form
Private ds As DataSet
Private myGrid As DataGrid
Shared Sub Main()
Application.Run(New DataGridSample)
End Sub

Private Sub ConnectToData()
Dim AppPath As String = Replace(Replace(Application.ExecutablePath,
Application.ProductName + ".exe", ""), Application.ProductName + ".exe", "")
& "Recept.mdb"
Dim cString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
AppPath
Dim cn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection(cString)
Dim adpTables As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
adpTables.TableMappings.Add("Table", "Kött")
cn.Open()
Dim cmdTable As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM
Kryddor", cn)
cmdTable.CommandType = CommandType.Text
adpTables.SelectCommand = cmdTable
ds = New DataSet("Customers")
adpTables.Fill(ds)
cn.Close()
Dim GridTableStyle As DataGridTableStyle = New DataGridTableStyle
GridTableStyle.MappingName = "Kött"
Me.myGrid.TableStyles.Add(GridTableStyle)
AddStyle(myGrid,ds)
End Sub
Private Sub AddStyle(ByVal grdSrc As DataGrid, ByVal dataS As DataSet)
Dim aCboCol As MyComboColumn = New MyComboColumn(dataS, "KöttID", "", False)
aCboCol.Width = 129
aCboCol.MappingName = "KöttID"
aCboCol.HeaderText = "Kött"
myGrid.TableStyles("Kött").GridColumnStyles.Add(aCboCol)
End Sub
Private Sub DataGridSample_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ConnectToData()
End Sub
End Class

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

Me.cboDatum.DataSource = ds.Tables(1)
cboDatum.DisplayMember = "KöttID"
cboDatum.ValueMember = ""


QuestionDataGrid Pin
Amarni14-Jul-06 22:40
Amarni14-Jul-06 22:40 
AnswerRe: DataGrid Pin
RookieThomas14-Jul-06 23:30
RookieThomas14-Jul-06 23:30 
QuestionMove Form Pin
Socheat.Net14-Jul-06 15:59
Socheat.Net14-Jul-06 15:59 
AnswerRe: Move Form Pin
Dave Kreskowiak14-Jul-06 16:28
mveDave Kreskowiak14-Jul-06 16:28 
AnswerRe: Move Form Pin
The ANZAC14-Jul-06 16:51
The ANZAC14-Jul-06 16:51 
GeneralRe: Move Form Pin
The ANZAC15-Jul-06 18:35
The ANZAC15-Jul-06 18:35 
GeneralRe: Move Form Pin
Dave Kreskowiak16-Jul-06 1:42
mveDave Kreskowiak16-Jul-06 1:42 
QuestionRunning Executables Pin
The ANZAC14-Jul-06 12:47
The ANZAC14-Jul-06 12:47 
AnswerRe: Running Executables Pin
Jun Du14-Jul-06 14:39
Jun Du14-Jul-06 14:39 
GeneralRe: Running Executables Pin
The ANZAC14-Jul-06 16:48
The ANZAC14-Jul-06 16:48 
AnswerRe: Running Executables Pin
Keith Malwitz16-Jul-06 19:18
Keith Malwitz16-Jul-06 19:18 
Questionhow to apply texture Pin
syed imran azmat14-Jul-06 11:23
syed imran azmat14-Jul-06 11:23 
QuestionProblem with DeviceIoControl Pin
gupta_san4114-Jul-06 11:08
gupta_san4114-Jul-06 11:08 
QuestionBulk Insertion into database from asp.net Pin
montu337714-Jul-06 10:45
montu337714-Jul-06 10:45 
AnswerRe: Bulk Insertion into database from asp.net Pin
Kschuler14-Jul-06 11:28
Kschuler14-Jul-06 11:28 
GeneralRe: Bulk Insertion into database from asp.net Pin
montu337718-Jul-06 5:03
montu337718-Jul-06 5:03 
Questionrichtextboxes and .doc files [modified] Pin
giddy_guitarist14-Jul-06 7:24
giddy_guitarist14-Jul-06 7:24 

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.