Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to Set Display Text Of ComboBox In Datagridview to for example :"Click Here To Open Drop Down List"

Set Text In Combo Box Is Simple but Set Text To Datagridviewcombobox is not like combobox

Any One Who Found Useful Link please help me,because i didnt find any link related to my problem

I mean,i want to show a text in combo box before user click on it

Edited:

I think i didnt explained my question well,see this picture please:

combo box without display text[^]

and this picture :

combo box with display text[^]

i want to make my combo box like second picture(i want to show an string like : "click here to open drop down list" in combo box before user click)
Posted
Updated 21-May-12 3:51am
v5

hi dear

If you are fetching data for combo from database then you can use union query for select "Select combobox" like

SQL
select Val,Txt from tblComboMaster
union All
select '0' as Val, 'Select combobox' as Txt
order by Val


after it bind selected value = 0 from combobox

Thanks
 
Share this answer
 
Comments
arashmobileboy 21-May-12 9:51am    
please see my edited question
Hi ,
Check this
XML
<div>
           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        onrowdeleting="GridView1_RowDeleting">
        <Columns>
            <asp:BoundField DataField="dd" HeaderText="dd" SortExpression="dd" />
            <asp:TemplateField HeaderText="ddd" SortExpression="ddd">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ddd") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ddd") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="cate" SortExpression="cate">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataSourceID="SqlDataSource12" DataTextField="cate" DataValueField="id"
                        SelectedValue="<%# Bind('cate') %>">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource12" runat="server"
                        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                        SelectCommand="SELECT * FROM [cate]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("cate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
        SelectCommand="SELECT * FROM [View_1]"></asp:SqlDataSource>
           <br />

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
arashmobileboy 21-May-12 9:52am    
my question is in winforms not asp.net

please see my edited question
Try this :-

//Add Combo Box Column
 DataGridViewComboBoxColumn comboBoxCol = new
 DataGridViewComboBoxColumn();
 comboBoxCol.Name = "Name1";
 comboBoxCol.HeaderText = "HeaderText1";
 DataGridView1.Columns.Add(comboBoxCol);
 comboBoxCol.Width = 80;
 //comboBoxCol.ReadOnly = false; //Enable Editing

 //Now you can add multiple columns to the combobox.
 comboBoxCol.Items.Add("COLUMN1");
 comboBoxCol.Items.Add("COLUMN2");
 comboBoxCol.Items.Add("COLUMN3");


Hope This Help !!
 
Share this answer
 
v2
Comments
arashmobileboy 21-May-12 9:52am    
i tested this way but it doesnt show ant text


please see my edited question
First I added my items to combobox(i fetched data from sql server database with datareader and added them to combo box) then i added this properties to my datagridviewcolumn(dgv_col) :

dgv_col.DataPropertyName="name"
dgv_col.DisplayMember="name"
dgv_col.ValueMember="id"

name is a field in my table and id is the identity for each name

And Finally it Solved :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900