473,503 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with dataGridView column type...

37 New Member
Hi,
I have a simple problem. I have a DataGridView populated from dataSet. I want to change the type of one of the columns from text to combo. All cells in that column will contain same data.
Expand|Select|Wrap|Line Numbers
  1. dgwEmployersList.DataSource                = Employee.getAllEmployers();
  2. dgwEmployersList.DataMember                = "employer";
  3.  
  4. dgwEmployersList.SelectionMode            = DataGridViewSelectionMode.FullRowSelect;
  5. dgwEmployersList.MultiSelect            = false;
  6. dgwEmployersList.EditMode                = DataGridViewEditMode.EditOnEnter;
  7. dgwEmployersList.Font                    = new Font( "Arial", 10 );
  8.  
  9. dgwEmployersList.Columns[0].HeaderText    = "ID";
  10. dgwEmployersList.Columns[0].Width        = 50;
  11. dgwEmployersList.Columns[0].ReadOnly    = true;
  12.  
  13. dgwEmployersList.Columns[1].HeaderText    = "Name";
  14. dgwEmployersList.Columns[1].Width        = 200;
  15.  
  16. dgwEmployersList.Columns[2].HeaderText    = "Post";
  17. dgwEmployersList.Columns[2].Width        = 100;
  18. I want to change this column's type to combo...???How???
  19.  
  20.  
Thanks...
Dec 23 '07 #1
1 1383
thenmozhivasanraj
11 New Member
work it out as follows its sort out your problem

Copy the following code in Page load
Expand|Select|Wrap|Line Numbers
  1.  DataTable mydatatable = new DataTable();
  2.         DataColumn mydatacol = new DataColumn("Name", Type.GetType("System.String"));
  3.         mydatatable.Columns.Add(mydatacol);
  4.         DataRow Mydatarow;
  5.         Mydatarow = mydatatable.NewRow();
  6.         Mydatarow["Name"] = "asdsad";
  7.         mydatatable.Rows.Add(Mydatarow);
  8.         Mydatarow = mydatatable.NewRow();
  9.         Mydatarow["Name"] = "wewewe";
  10.         mydatatable.Rows.Add(Mydatarow);
  11.  
  12.         GridView1.DataSource = mydatatable.DefaultView;
  13.         GridView1.DataBind();
  14.  
  15.         GridViewRow bl_gridviewrow;
  16.  
  17.         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  18.         {
  19.             bl_gridviewrow = GridView1.Rows[i];
  20.             DropDownList bl_ddl = (DropDownList)bl_gridviewrow.FindControl("ddl1");
  21.             bl_ddl.Visible = true;
  22.             TextBox bl_txt = (TextBox)bl_gridviewrow.FindControl("txt1");
  23.             bl_txt.Visible = false;
  24.         }
  25.  
Copy the following in htmlsource view
Expand|Select|Wrap|Line Numbers
  1.  <div>
  2.         <asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 247px; position: absolute;
  3.             top: 51px" AutoGenerateColumns="False">
  4.             <Columns>
  5.  
  6.                 <asp:TemplateField>
  7.                 <ItemTemplate>
  8.                     <asp:TextBox id="txt1" Text=sdfsdf runat="server">
  9.                     </asp:TextBox>
  10.                     <asp:DropDownList ID="ddl1" runat="server">
  11.                     </asp:DropDownList>
  12.                     </ItemTemplate>
  13.                 </asp:TemplateField>
  14.             </Columns>
  15.         </asp:GridView>
  16.  
  17.     </div>
  18.  
run the project you can find the result
Dec 26 '07 #2

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

Similar topics

1
2294
by: Rich | last post by:
Hello, I am reading data from a sql server table that is under replication. This table has the replicatin GUID column that is generated with replicatin. I am reading the data from a...
2
16646
by: Marc Solé | last post by:
Hello, I want to insert an image to a specific column of a dataGridWiew. I explain what I'm doing: - I define the ColumnType as a DataGridViewImageColumn. - I select the image (an icon of...
4
21269
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv,...
8
11499
by: Brian Pelton | last post by:
This is on .Net 2.0 in a WinForms application. I have a DataGridView that is bound to a BindingSource. The DataGridView has 3 columns. The first two are "normal" text columns and the last is a...
2
6101
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It...
0
1032
by: TonyJ | last post by:
Hello! I have earlier used a grid called flygrid where everything had to be done by coding. I use VS2005 so I have this DataGridView which I can't really understand how to use. I mean what...
1
3353
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
9
3406
by: Miro | last post by:
My current headache is proper is with the datagridview I am starting to realize that a DataGridView within vs2008 is not as 'robust' as a 'textboxfield' by default for example. Example: A...
1
1842
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've been away from web programming for a while and I have a situation that's new to me. I'm using VB/Dot Net 2.0. I've created an xsd (dataset) in the project and dragged some fields from a...
0
5635
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
7201
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
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
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...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.