C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Combobox in Datagridview


Posted Date: 19 Jul 2008      Total Responses: 2

Posted By: janu       Member Level: Silver     Points: 1



Hi Friends ,

Can any send the coding of


Combobox binding data from database it vl display in the Datagridview ...


How to bind the values to DatagridviewCombobox .....


Windows Application With C#.net .............

regards,

janus





Responses

Author: Ashokkumar    19 Jul 2008Member Level: GoldRating:     Points: 5

hi this code in VB.net to convert C#
Dim OleCB2 As New OleDbCommandBuilder(daSubCategory)
daSubCategory.Fill(dsSubCategory)


CType(dgvAlert.Columns(1), DataGridViewComboBoxColumn).DataSource = dsCategory.Tables(0)
CType(dgvAlert.Columns(1), DataGridViewComboBoxColumn).DisplayMember = "CT_Description"
CType(dgvAlert.Columns(1), DataGridViewComboBoxColumn).ValueMember = "CT_Code"



Author: chandramohan    19 Jul 2008Member Level: GoldRating:     Points: 1

Imports System.Data
Imports System.Data.SqlClient

PublicClass frmCboBoxTest

'Declare Object and Database Connection String
Dim objConnection AsNew SqlConnection _
("server=OFFSITE-223181S\SQLEXPRESS;database=TemDb;Trusted_Connection=yes;")


'SELECT statement for the ComboBox
Dim objDataAdapter2 AsNew SqlDataAdapter( _
"SELECT Satellite.SatelliteSccNum4 From Satellite", objConnection)


'SELECT statement for DataGridView And
'JOIN WHERE Signal Table Transponder ID is Equal to Transponder Table Transponder ID
Dim objDataAdapter AsNew SqlDataAdapter( _
"SELECT * FROM Signal, objConnection)

'ComboBox1 connection Information
Dim objDataSet2 As DataSet
Dim objDataView2 As DataView

'DataGrid connection information
Dim objDataSet As DataSet
Dim objDataView As DataView

PrivateSub FillDataSetAndView()

'ComboBox1
objDataSet2 = New DataSet
objDataView2 = New DataView(objDataSet2.Tables("Satellite"))

'DataGridView
objDataSet = New DataSet
objDataView = New DataView(objDataSet.Tables("Signal"))


'Fill the ComboBox with data
objDataAdapter2.Fill(objDataSet2, "Satellite")

'Fill the DataGrid with data
objDataAdapter.Fill(objDataSet, "Signal")

EndSub

PrivateSub BindFields()

'Clear any previous bindings
ComboBox1.DataBindings.Clear()
grdCboTest.DataBindings.Clear()

'Set the ComboBox properties to bind it to the data and
'Add Satellite SCC #s' from the Satellite DB
ComboBox1.DataSource = objDataSet2.Tables("Satellite")
ComboBox1.DisplayMember = "SatelliteSccNum4"
ComboBox1.ValueMember = "SatelliteSccNum4"

EndSub

PrivateSub ComboBox1_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

If ComboBox1.SelectedIndex Then

'Open the database connection
objConnection.Open()

'Set the DataGridView properties to bind it to the data
grdCboTest.AutoGenerateColumns = True
grdCboTest.DataSource = objDataSet
grdCboTest.DataMember = "Signal"

'Close the Database connection
objConnection.Close()

'Fill the dataset and bind the fields
FillDataSetAndView()
BindFields()

EndIf

EndSub

PrivateSub frmCboBoxTest_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load

'Fill ComboBox and DataGridView with data from DB at Load
FillDataSetAndView()
BindFields()

'Set ComboBox Selected index to the 1st position or 0 index at Load
ComboBox1.SelectedIndex = 0

EndSub

PrivateSub btnExit_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

'Close application when btnExit is Clicked
Me.Close()

EndSub

EndClass



Post Reply
You must Sign In to post a response.
Next : button click event in windows application C#
Previous : ToolTips for Windows Forms ComboBox
Return to Discussion Forum
Post New Message
Category: Windows

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use