Add Control to WinForms DataGrid (Part-2)

VB - Windows Control , Posted at : Feb/11/2007   [Click this link to download code sample]
1511 Views   0 Comments

Here's the code of Part-2 :

   1:  #Region "Form's Events"
   2:      Private Sub ControlInDataGrid_Load(ByVal sender As System.Object, _
   3:      ByVal e As System.EventArgs) Handles MyBase.Load
   4:          Me.CreateControlInDataGrid()
   5:          Me.FillDataToCombo()
   6:          Me.CreateDataSource()
   7:          Me.MyDataGridStyle()
   8:      End Sub
   9:  #End Region
  10:   
  11:  #Region "CommandButton's Events"
  12:      Private Sub Button1_Click(ByVal sender As System.Object, _
  13:      ByVal e As System.EventArgs) Handles Button1.Click
  14:          '//save
  15:          Try
  16:              'update data
  17:              daProducts.Update(dsProducts.Tables(0))
  18:   
  19:              'refresh data
  20:              Me.FillDataToCombo()
  21:              Me.CreateDataSource()
  22:              Me.MyDataGridStyle()
  23:   
  24:              MsgBox("Updated")
  25:          Catch ex As Exception
  26:              Me.dsProducts.Tables(0).RejectChanges()
  27:              MsgBox(ex.Message)
  28:          End Try
  29:      End Sub
  30:   
  31:      Private Sub Button2_Click(ByVal sender As System.Object, _
  32:      ByVal e As System.EventArgs) Handles Button2.Click
  33:          '//batal
  34:          Me.dsProducts.Tables(0).RejectChanges()
  35:      End Sub
  36:  #End Region
  37:   
  38:  #Region "Combo CategoryID Events"
  39:      Private Sub cboCategoryID_MouseEnter(ByVal sender As Object, _
  40:      ByVal e As System.EventArgs) Handles cboCategoryID.MouseEnter
  41:          Try
  42:              'categoryid ada di kolom 3 (index dimulai dari 0)
  43:              Dim currentID As String = DataGrid1.Item( _
  44:              Me.DataGrid1.CurrentRowIndex, 3).ToString.Trim
  45:   
  46:              Dim intIndex As Integer = cboCategoryID.FindString(currentID)
  47:              Me.cboCategoryID.SelectedIndex = intIndex
  48:          Catch ex As Exception
  49:          End Try
  50:      End Sub
  51:   
  52:      Private Sub cboCategoryID_SelectedIndexChanged(ByVal sender As Object, _
  53:      ByVal e As System.EventArgs) Handles _
  54:      cboCategoryID.SelectedIndexChanged
  55:          If Me.cboCategoryID.Text <> "" Then
  56:              Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex, 3) = _
  57:              Me.cboCategoryID.Text
  58:          End If
  59:      End Sub
  60:  #End Region
  61:   
  62:  #Region "Combo SupplierID Events"
  63:      Private Sub cboSupplierID_MouseEnter(ByVal sender As Object, _
  64:      ByVal e As System.EventArgs) Handles cboSupplierID.MouseEnter
  65:          Try
  66:              'supplierid ada di kolom 2 (index dimulai dari 0)
  67:              Dim currentID As String = DataGrid1.Item( _
  68:              DataGrid1.CurrentRowIndex, 2).ToString
  69:              Dim intIndex As Integer = cboSupplierID.FindString(currentID)
  70:              Me.cboSupplierID.SelectedIndex = intIndex
  71:          Catch ex As Exception
  72:          End Try
  73:      End Sub
  74:   
  75:      Private Sub cboSupplierID_SelectedIndexChanged(ByVal sender As Object, _
  76:      ByVal e As System.EventArgs) Handles cboSupplierID.SelectedIndexChanged
  77:          If Me.cboSupplierID.Text <> "" Then
  78:              DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) = _
  79:              cboSupplierID.Text
  80:          End If
  81:      End Sub
  82:  #End Region
  83:   
  84:  #Region "DataGrid's Events"
  85:      Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, _
  86:      ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
  87:          Try
  88:              Dim currentID As String = DataGrid1.Item( _
  89:              DataGrid1.CurrentRowIndex, 2).ToString
  90:   
  91:              Dim intIndex As Integer = cboSupplierID.FindString(currentID)
  92:              cboSupplierID.SelectedIndex = intIndex
  93:   
  94:              currentID = DataGrid1.Item(DataGrid1.CurrentRowIndex, 3).ToString
  95:              intIndex = cboCategoryID.FindString(currentID)
  96:              cboCategoryID.SelectedIndex = intIndex
  97:          Catch ex As Exception
  98:          End Try
  99:      End Sub
 100:  #End Region

[Comments]

[Write your comment]
Name (required)
Email (required-will not published)
 
Comment

ZMQN
Input code above below (Case Sensitive) :
About Me 
Rully Yulian MF
My Name is Rully Yulian Muhammad Firmansyah. I am an IT Trainer, IT Consultant and Application Developer spesializing in Microsoft .NET technology and SQL Server database. I live in Bandung, Indonesia. My hobby is to play Guitar. [Read More...]
Top Download 
Bagaimana caranya menginstal database ketika deploying sebuah aplikasi? : Downloaded 3175 times  
Change Group,Sort Order, Filtering By Date in Crystal Reports : Downloaded 2592 times  
Mapping Hak Akses User Pada MenuStrip Sampai Control Button : Downloaded 2180 times  
Simple Voice Engine Application With Sound Player Class... : Downloaded 2127 times  
WinForms DataGrid Paging With SqlDataAdapter : Downloaded 1806 times  
Article Category 
Links 
Award 
Certifications 
MOS 2007
MCAS
MCT
MCPD
MCTS
MCAD.NET
ASP.NET Brainbench
Native Enterprise 
Follow Me 
Facebook   LinkedIn   Twitter
Syndication 
Hosted By 
Native Enterprise News