473,656 Members | 2,756 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 1393
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
2305
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 dataAdapter/Dataset using a dataview which is the data source for a datagridview control. When I scroll horizontally in the datagridview control and reach this GUID column (which is not at the end of the table) it raises the datagridview dataError event. ...
2
16658
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 open folder). When I accept, in the design form, appears in the ImageColumn the typical red cross of an image not found.
4
21292
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, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I access the cb and its checked status? How to iterate thru dgv? Dim cbSelCol As New DataGridViewCheckBoxColumn
8
11525
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 combo box column. Data binding is working fine for the first two columns. I am able to edit values and persist them back to the bound object and ultimately back to the database.
2
6116
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 seems to return an error: "Formatted Value of the cell has wrong type". It works fine when the datagridview's editmode property is
0
1035
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 can be done by using different feature like add column/edit column and so and
1
3372
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: 1) export to excel button exports the visible columns from the datagridview to excel (this works fine)
9
3413
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 Textbox field can have masking, you can add easy validation and so on. Just adding a dummy datagridview to a form, databounding it, and allowing editing works - but is not dummy proof.
1
1845
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 table into it. This query is intended as readonly. I've already successfully bound a datagridview to the query using an Object Data Source. The query result can easily return several hundred records so paging is enabled. As I said, the query...
0
5646
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 blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
0
8297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.