C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Customizing the DataGrid with ComboBox


Posted Date: 11 Jul 2006    Resource Type: Articles    Category: .NET Framework
Author: AnnyGMember Level: Gold    
Rating: 1 out of 5Points: 10



Step to Follow.....

Step 1: 'Declare a WithEvent for ComboBox
Private WithEvents cboData As New ComboBox
Dim myDataSet As DataSet

Step 2: Create a method for making a DataSet with Hard Code........

Private Sub makeDataSet()
myDataSet = New DataSet("myDataSet")
Dim tCust As New DataTable("myTable")

Dim c1 As New DataColumn("Column1")
Dim c2 As New DataColumn("Column2")
Dim c3 As New DataColumn("Column3")

tCust.Columns.Add(c1)
tCust.Columns.Add(c2)
tCust.Columns.Add(c3)

myDataSet.Tables.Add(tCust)

Dim newRow1 As DataRow
Dim i As Integer
For i = 1 To 3
newRow1 = tCust.NewRow()
tCust.Rows.Add(newRow1)
Next i

tCust.Rows(0)("Column1") = "Column1"
tCust.Rows(1)("Column1") = "Column1"
tCust.Rows(2)("Column1") = "Column1"

tCust.Rows(0)("Column2") = "Column2"
tCust.Rows(1)("Column2") = "Column2"
tCust.Rows(2)("Column2") = "Column2"

End Sub

Step 3: Create method for Customizing the DataGrid Control Columns
Private Sub setColumns()

Dim tsTblStyle As DataGridTableStyle
tsTblStyle = New DataGridTableStyle

If myDataSet.Tables(0).Rows.Count > 0 Then

tsTblStyle.MappingName = myDataSet.Tables(0).ToString()
DataGrid1.TableStyles.Add(tsTblStyle)

Dim dgColumn1 As New DataGridTextBoxColumn
dgColumn1 = CType(DataGrid1.TableStyles(0).GridColumnStyles.Item(0), DataGridTextBoxColumn)
dgColumn1.TextBox.MaxLength = 50
DataGrid1.TableStyles(0).GridColumnStyles.Item(0).Width = 75

Dim dgColumn2 As New DataGridTextBoxColumn
dgColumn2 = CType(DataGrid1.TableStyles(0).GridColumnStyles.Item(1), DataGridTextBoxColumn)
dgColumn2.TextBox.MaxLength = 100
DataGrid1.TableStyles(0).GridColumnStyles.Item(1).Width = 75

Dim dgrtxtCF As New DataGridTextBoxColumn
DataGrid1.TableStyles(0).GridColumnStyles.Item(2).Width = 100
dgrtxtCF = CType(DataGrid1.TableStyles(0).GridColumnStyles(2), DataGridTextBoxColumn)
dgrtxtCF.TextBox.Controls.Add(cboData)
cboData.Width = 99
cboData.DropDownStyle = ComboBoxStyle.DropDownList
cboData.Items.Add("One")
cboData.Items.Add("Two")
cboData.Items.Add("Three")
cboData.Items.Add("Four")
cboData.Items.Add("Five")
End If
End Sub

Step 4: Calling methods in Form_load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
makeDataSet()
DataGrid1.SetDataBinding(myDataSet, "myTable")
setColumns()
End Sub

Step 5:
Private Sub cboData_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboData.SelectedValueChanged
DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber) = cboData.SelectedItem
End Sub




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Difference among Int32.Parse(), Convert.ToInt32(), and Int32.TryParse()
Previous Resource: Accessing the Values from Registry
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use