Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I saw very a lot documents but not found resolve"
I try the next:

XML
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();

            ListCards.Columns.Add(btn);
            btn.HeaderText = "Status";
            btn.Text = "Status";
            btn.Name = "btn_status";

ListCards.Columns[1].Name = r.GetString("CardInfo");
            ListCards.Columns[2].Name = r.GetString("StartDayD");
            ListCards.Columns[3].Name = r.GetString("EndDayD");
            ListCards.Columns[4].Name = r.GetString("ExecuteDay");
            ListCards.Columns[5].Name = r.GetString("Username");
            ListCards.Columns[6].Name = r.GetString("Mobile");
            ListCards.Columns[7].Name = r.GetString("IdUser");

<pre lang="cs">string[] row = new string[] {obj.CardInfo, start_day, end_day, execute_day, obj.Username, obj.Mobile, Id_User, btn  };
                ListCards.Rows.Add(row);&lt;/pre&gt;</pre>


I try insert btn for every row (see please last param at string[] row)

What i do wrong? Help me please
Posted
Updated 16-Apr-13 23:12pm
v2
Comments
[no name] 17-Apr-13 5:30am    
So, i can create Button such:

Button Button = new Button();
Button.Text = "Active";
Button.Width = 100;
Button.Height = 30;

And i can not add object Button to row = new string[] {obj.CardInfo, start_day, end_day, execute_day, obj.Username, obj.Mobile, Id_User, Button }; Because it is string row. I hope you are undestand me
[no name] 17-Apr-13 5:36am    
Are you trying to add a button to each row of the datagrid?

1 solution

You can add the column with that :

C#
dataGridView1.Columns.Add(new DataGridViewButtonColumn()
                {
                Name="ColumnName",
                HeaderText="Header"
                // add here properties for the new column
                }
             );
 
Share this answer
 
Comments
[no name] 17-Apr-13 5:43am    
I need add one column, but at loop i want add last row with button.
[no name] 17-Apr-13 5:45am    
ListCards.ColumnCount = 8;
Button Button = new Button();
Button.Text = "Active";
Button.Width = 100;
Button.Height = 30;

foreach (var obj in BLL.Cards.GetListCards())
{
object row = new object[] { obj.CardInfo, obj.StartDay, obj.EndDay, obj.ExicuteDay, obj.IdUser, obj.Username, obj.Status, Button };
ListCards.Rows.Add(row);

}

But is wrong
Thomas Barbare 17-Apr-13 5:47am    
You wants the button only on the last row, right ?
[no name] 17-Apr-13 5:53am    
Again! i have 3 columns: Name, Ststus, Action.
After i form row, that add to Datagrid.
For column Name and Status i from row as: string[] row = new string[] {obj.CardInfo, start_day, end_day }
Attention: and last field for every row must be Button
In result i must get table view:

Name Status Action
Ol 1 Button1
PO 2 Button2
[no name] 17-Apr-13 5:54am    
All this i must do at loop, where i form rows and add it

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