Add Control to WinForms DataGrid (Part-2)

Posted at : Feb/11/2007
3038 Views | 2 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]

Santo (Feb/19/2013 01:13:08)

Kang Rully mau tanya,apakah datagrid sama dengan datagridview(maklum masih baru di vb.net:D)?soalnya di visual studio 2010 pada panel toolbox tidak ada fitur datagrid.. 

Rully (Feb/23/2013 10:56:02)

Santo > Tidak terlalu berbeda jauh, secara umum fungsinya sama kok :) ...cuma memang sekarang yang ada itu DataGridView :)


[Write your comment]

Name (required)

Email (required-will not published)

Comment
CVDH
Input code above below (Case Sensitive) :

ABOUT ME

Rully Yulian MF
Rully Yulian Muhammad Firmansyah | Founder & IT Trainer Native Enterprise | MCT (2008-2019) | MVP (2009-2016) | Xamarin Certified Professional | MTA | MCAD | MCPD | MOS | Bandung, West Java, Indonesia.

[Read More...]

TOP DOWNLOAD

Mapping Hak Akses User Pada MenuStrip Sampai Control Button
downloaded 6983 times

Bagaimana caranya menginstal database ketika deploying sebuah aplikasi?
downloaded 4893 times

Simple Voice Engine Application With Sound Player Class...
downloaded 4045 times

Change Group,Sort Order, Filtering By Date in Crystal Reports
downloaded 3460 times

WinForms DataGrid Paging With SqlDataAdapter
downloaded 2881 times


LINKS

CERTIFICATIONS

Xamarin Certified
MOS 2007
MCT
MCPD
MCTS
MCAD.NET
ASP.NET Brainbench

NATIVE ENTERPRISE

Native Enterprise - IT Training

FOLLOW ME

Youtube  Facebook  Instagram  LinkedIn   Twitter

RSS


NATIVE ENTERPRISE NEWS

© Copyright 2006 - 2024   Rully Yulian MF   All rights reserved.