Click here to Skip to main content
15,925,444 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionDatagridView Pin
Socheat.Net24-Jan-07 0:13
Socheat.Net24-Jan-07 0:13 
AnswerRe: DatagridView Pin
Ahmed El-Badry24-Jan-07 1:06
Ahmed El-Badry24-Jan-07 1:06 
QuestionPlz help me Pin
Ahmed El-Badry24-Jan-07 0:07
Ahmed El-Badry24-Jan-07 0:07 
Questionhow to add comboBox as a column in DatagridView? Pin
priya_p23324-Jan-07 0:01
priya_p23324-Jan-07 0:01 
AnswerRe: how to add comboBox as a column in DatagridView? Pin
tonymathewt24-Jan-07 1:44
professionaltonymathewt24-Jan-07 1:44 
GeneralRe: how to add comboBox as a column in DatagridView? Pin
priya_p23324-Jan-07 18:15
priya_p23324-Jan-07 18:15 
AnswerRe: how to add comboBox as a column in DatagridView? [modified] Pin
atulks.in24-Jan-07 20:18
atulks.in24-Jan-07 20:18 
AnswerRe: how to add comboBox as a column in DatagridView? Pin
tonymathewt24-Jan-07 22:43
professionaltonymathewt24-Jan-07 22:43 
I am sorry about posting ASP code.
You can not set a datatable or dataview as the datasource for a combobox inside a Grid. In the following code I have given an ArrayList as the datasource for it. You can easily store a column into an ArrayList that is also done here. Please note that you have to set the AutoGenerateColumns property of the Grid to 'false' and add col's manually. I hope you know how to do that. The columns from the table 'product' which is in the database are: 'pname' and 'price'. And the manually added colmn names of the Grid 'Dg_Test' are: 'pname', 'Price' and 'type'. The third column in Dg_Test is the one you want that is of type DataGridViewComboBoxColumn. Other two pname and Price are DataGridViewTextBoxColumn. The value for third col'n is taken from a different table 'producttype' with field 'type'. I have not added any code regarding database connectivity for OleDbConnection.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Fill_Grid()
End Sub
Private Sub Fill_Grid()
Dim stt As String = "Select * from product"
Dim Cmd As OleDbCommand
Dim Adaptor As OleDbDataAdapter
Dim Ds As New DataSet
Dim dt As DataTable
Dim arList As New ArrayList

'Add columns manually using smart tag of the GridView column names are pname,Price,type
Dg_Test.AutoGenerateColumns = False
dbObj.OpenConnection()

Cmd = dbObj.ReturnOledbCommand(stt)
Adaptor = New OleDbDataAdapter(Cmd)
Adaptor.Fill(Ds, "product")
dt = Ds.Tables("product")
Me.Dg_Test.DataSource = dt

'Type cast the column pname and Price to DataGridViewTextBoxColumn and set the DataPropertyName to the
'field names in the database
Dim Name As DataGridViewTextBoxColumn = CType(Dg_Test.Columns("pname"), DataGridViewTextBoxColumn)
Name.DataPropertyName = "pname" 'pname is the field from the table in database
Dim Price As DataGridViewTextBoxColumn = CType(Dg_Test.Columns("Price"), DataGridViewTextBoxColumn)
Price.DataPropertyName = "price" 'price is the field from the table in database

'Datasource for DataGridViewComboBoxColumn
stt = "Select type from producttype"
Cmd = dbObj.ReturnOledbCommand(stt)
Adaptor = New OleDbDataAdapter(Cmd)
Adaptor.Fill(Ds, "producttype")
dt = Ds.Tables("producttype")

'Insert elemants into array list from dt
For Each dr As DataRow In dt.Rows
arList.Add(dr(0)) 'dr contains only one column
Next

Dim Type As DataGridViewComboBoxColumn = CType(Dg_Test.Columns("type"), DataGridViewComboBoxColumn)
Type.DataSource = arList 'Datasource is set to an arraylist


dbObj.CloseConnection()

End Sub
QuestionDatabase error Pin
lanache23-Jan-07 23:58
lanache23-Jan-07 23:58 
AnswerRe: Database error Pin
atulks.in24-Jan-07 19:49
atulks.in24-Jan-07 19:49 
GeneralRe: Database error Pin
lanache24-Jan-07 23:04
lanache24-Jan-07 23:04 
AnswerRe: Database error Pin
atulks.in25-Jan-07 0:11
atulks.in25-Jan-07 0:11 
QuestionDatabase error Pin
lanache23-Jan-07 23:47
lanache23-Jan-07 23:47 
AnswerRe: Database error Pin
Ahmed El-Badry24-Jan-07 0:39
Ahmed El-Badry24-Jan-07 0:39 
GeneralRe: Database error Pin
lanache24-Jan-07 22:20
lanache24-Jan-07 22:20 
QuestionIs this possible??????? Pin
FeRtoll23-Jan-07 22:52
FeRtoll23-Jan-07 22:52 
AnswerRe: Is this possible??????? Pin
IqbalVB25-Jan-07 20:03
IqbalVB25-Jan-07 20:03 
GeneralRe: Is this possible??????? Pin
FeRtoll28-Jan-07 23:21
FeRtoll28-Jan-07 23:21 
Questioncreating a batch file to generate dll from code files of vb6 and vb.net Pin
atulks.in23-Jan-07 22:19
atulks.in23-Jan-07 22:19 
AnswerRe: creating a batch file to generate dll from code files of vb6 and vb.net Pin
Ahmed El-Badry24-Jan-07 0:42
Ahmed El-Badry24-Jan-07 0:42 
GeneralRe: creating a batch file to generate dll from code files of vb6 and vb.net Pin
atulks.in24-Jan-07 19:41
atulks.in24-Jan-07 19:41 
QuestionFile Watcher Question Pin
FeRtoll23-Jan-07 21:37
FeRtoll23-Jan-07 21:37 
QuestionCustom control Textbox Pin
Vikash Yadav23-Jan-07 21:16
Vikash Yadav23-Jan-07 21:16 
AnswerRe: Custom control Textbox Pin
Christian Graus23-Jan-07 22:03
protectorChristian Graus23-Jan-07 22:03 
GeneralRe: Custom control Textbox Pin
Vikash Yadav23-Jan-07 23:14
Vikash Yadav23-Jan-07 23:14 

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.