473,387 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ComboBox in Datagridview in vb.net2005

mafaisal
142 100+
Hello

I am Using vb.net2005
My Doubt is When i bind database to datagridview how to create combobox in that
my code is
StrSQL = "Select SlNo,Fname,Relation,Age,gender,Others From EmpDet a,EmpMast b Where a.Id = b.Id And b.Id = " & Val(TxtID.Text) & " "
Dap = New OleDb.OleDbDataAdapter(StrSQL, Con)
Dap.Fill(DstDet, "DstDet")
DGView.DataSource = DstDet
DGView.DataMember = "DstDet"

here the colum of gender coming in Combobox hw that is created...?
Jan 16 '08 #1
2 2193
dip_developer
648 Expert 512MB
Hello

I am Using vb.net2005
My Doubt is When i bind database to datagridview how to create combobox in that
my code is
StrSQL = "Select SlNo,Fname,Relation,Age,gender,Others From EmpDet a,EmpMast b Where a.Id = b.Id And b.Id = " & Val(TxtID.Text) & " "
Dap = New OleDb.OleDbDataAdapter(StrSQL, Con)
Dap.Fill(DstDet, "DstDet")
DGView.DataSource = DstDet
DGView.DataMember = "DstDet"

here the colum of gender coming in Combobox hw that is created...?
just create a dataset with another sql query which selects the gender....and set the datasource of the combo to that dataset...

see how....

Expand|Select|Wrap|Line Numbers
  1.  public DataSet PopulateDropDownList() 
  2. {
  3. SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
  4. SqlDataAdapter ad = new SqlDataAdapter("SELECT DISTINCT gender FROM EmpDet", myConnection);
  5. DataSet ds = new DataSet();
  6. ad.Fill(ds, "tblgender");
  7. return ds; 
  8. }
  9.  
Now let's see where we call this method...........
Expand|Select|Wrap|Line Numbers
  1.  
  2. <ItemTemplate>
  3. <asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# PopulateDropDownList() %>" 
  4. DataTextField="Gender" DataValueField = "GenderID">
  5. </asp:DropDownList>
  6. </ItemTemplate>
  7.  
  8.  
Jan 17 '08 #2
mafaisal
142 100+
Hello

Thanx for reply
ok i under stand
My Prob is When we Bind dataset to datagridview i think all column as
datagridviewtextboxcolumn then hw to make datagridviewcomboboxcolumn in gendercolumn

Faisal

just create a dataset with another sql query which selects the gender....and set the datasource of the combo to that dataset...

see how....

Expand|Select|Wrap|Line Numbers
  1.  public DataSet PopulateDropDownList() 
  2. {
  3. SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
  4. SqlDataAdapter ad = new SqlDataAdapter("SELECT DISTINCT gender FROM EmpDet", myConnection);
  5. DataSet ds = new DataSet();
  6. ad.Fill(ds, "tblgender");
  7. return ds; 
  8. }
  9.  
Now let's see where we call this method...........
Expand|Select|Wrap|Line Numbers
  1.  
  2. <ItemTemplate>
  3. <asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# PopulateDropDownList() %>" 
  4. DataTextField="Gender" DataValueField = "GenderID">
  5. </asp:DropDownList>
  6. </ItemTemplate>
  7.  
  8.  
Jan 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
8
by: | last post by:
I am sure this has been asked and answered, but here goes anyway... VS.Net 2005, VB.Net How can you display more than one field in the displaymember property of a combobox inside the...
0
by: c_shah | last post by:
I have the controls on my form display the values of the currently selected row of the DataGridView. I am binding my DataGridView to a collection (Collection - which implements IBindingList...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
3
by: Przemek M. Zawada | last post by:
Dear Group, I'm developing sample window form, using DataGridView control, which is filled with data through BindingSource, which is based on type of object, as follow: public sampleClass {...
2
by: David Jackson | last post by:
Hello, I have an unbound DataGridView of which one of the columns is a ComboBox colum containing category data, plus an additional option called <newSo when the ComboBox is dropped down it looks...
0
by: Dom | last post by:
I have a datagridview control, and one column is a ComboboxColumn. I simply create a ComboboxColumn, add items to it, then add the column to the Datagridview control. If I were working with a...
3
by: DEC | last post by:
I have a VB application that's about 95% done. As usual, it's that last 5% that's got me stymied. The program is a Bill-of-material update program that interfaces with an SAP database. The BOM's...
7
by: harikap | last post by:
hi , here im using vb.net 2005how can i add radiobuttons as column to windows datagridview control plz help me....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.