Hello guys... I would like to ask if anyone can give me some simple code regarding on how to create a datagridview that has a customized button on 1 or 2 column of that table... by the way i want to retrieve the data based on my database items...this is the structure of my database... assuming my database is named as "CAFEMS" and the table name is "Computers"
id | name | status
--------------+---------------+------------
192.168.0.2 | PC-2 | Active
192.168.0.3 | PC-2 | Active
192.168.0.25 | PC-2 | Active
192.168.0.112 | PC-2 | Active
192.168.0.220 | PC-2 | Active
192.168.0.20 | PC-2 | Active
so my table "Computers" computers contain this records of ip addresses of computers and a specified name and its status... What i want is to display all this record in a datagridview but with a little twists... instead of just displaying 3 columns in the datagridview i want to add 2 more columns and all this additional column would contain a datagridviewbuttoncolumn i've search the net for some sample but cant seem to find one... i have some tutorial on how to retrieve data from the database dataset and mysqldataadapter but none of those tutorial seems to instruct on how to insert a button on certain column this is what i want
id | name | Activate | status | Inactive
--------------+-----------+------------+------------+-------------------|
192.168.0.2 | PC-2 | |aButton| | Active | |anotherButton| |
192.168.0.3 | PC-3 | |aButton| | Active | |anotherButton| |
192.168.0.25 | PC-5 | |aButton| | Active | |anotherButton| |
192.168.0.112 | PC-7 | |aButton| | Active | |anotherButton| |
192.168.0.220 | PC-9 | |aButton| | Active | |anotherButton| |
192.168.0.20 | PC-21 | |aButton| | Active | |anotherButton| |
As you can see im adding a button on the 3rd and 5th column how am i supposed to do it? i have this code so far but this code only retrieves the data from a database but i dont know how to insert the datagridviewbuttoncolumn on the retrieved data.... hope you can help me guys... this is my code
public static MySQLCommand command;
public static MySQLConnection con;
public static MySQLDataAdapter adapter;
public static void displayTable(DataGridView table, string query) {
if(con==null)
{
conSet();
}
command = con.CreateCommand();
command.CommandText = query;
try {
con.Open();
dataset = new DataSet();
dataset.CaseSensitive = true;
adapter = new MySqlDataAdapter();
adapter.SelectCommand = command;
adapter.TableMappings.Add("Table","tbl_ipstatus");
adapter.Fill(dataset);
DataGridViewButtonColumn button = new DataGridViewButtonColumn();
button.Text = "aButton";
table.DataSource = dataset.Tables["tbl_ipstatus"].DefaultView;
con.Close();
}catch(Exception e){
Console.WriteLine(e.Message);
}
}
Hope you can help me with my problem guys thanks in advance...