Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create DataGridView in table form and add a button after each coloumn?
    primarykey
    data
    text
    <p>I am a beginner in .Net. I am making an application where I have dropped a DataGridView on my Form and connect it with database. I want that on search command the data obtained to in table form that is one column of it to contain heading and other field associated to it.</p> <p>I have used this code to bind it with database.</p> <p>There are large number of columns. I want that datagridview to show only some columns initially and to show a "show more" button in the same row to see full information about the that row data. </p> <pre><code>private void viewsrchbtn_Click(object sender, EventArgs e) { try { SqlCommand cmd = Database.GetConnection().CreateCommand(); SqlDataAdapter da = new SqlDataAdapter(); if (viewbycombo.SelectedItem.ToString() == "Name") { cmd.CommandText = "select p.pname as 'Name',p.pfname as 'Father Name' ,p.pmname as 'Mother Name',p.pfhname as 'Family Head Name',p.pdob as 'Date of Birth',p.pgender as 'Gender',p.pedulvl as 'Education',p.pedu as 'Degree',p.pblood as 'Blood Group',p.gotra as 'Gotra',p.panth as 'Panth',p.pmarritalstatus as 'Marrital Status',s.psname as 'Spouse Name',s.psedulvl as 'Spouse Edu. Degree',s.psedu as 'Spouse Education',s.psblood as 'Spouse Blood Group',s.psdob as 'Spouse Date of Birth',c.pnochild as 'Number of Children',c.pcname as 'Child Name',c.pcblood as 'Child Blood Group',c.pcdob as 'Child Date of Birth',r.pres_add as 'Resident Address',pres_phone as 'Resident Ph.no ',pres_mobile as 'Resident Mobile no.',o.poccup_nature as 'Nature of Occupation',o.poccup_type as 'Type of Occupation',o.poccup_add as 'Office Address',o.pemail as 'Email id',o.poccup_phone as 'Office Ph.no',o.poccup_mobile as 'Office Mobile number'from personal as p join spouse as s on p.pid=s.pid join children as c on p.pid=c.pid join occup_contact as o on p.pid=o.pid join res_contact as r on p.pid=r.pid where pname='" + viewtxt.Text + "' "; } if (viewbycombo.SelectedItem.ToString() == "Phone Number") { cmd.CommandText = "Select * from personal where pfname='" + viewtxt.Text + "'"; } if (viewbycombo.SelectedItem.ToString() == "Father's Name") { cmd.CommandText = "Select * from personal where pname='" + viewtxt.Text + "'"; } if (viewbycombo.SelectedItem.ToString() == "Blood Group") { cmd.CommandText = "Select * from personal where pblood='" + viewtxt.Text + "'"; } cmd.CommandType = CommandType.Text; DataSet ds = new DataSet(); da.SelectCommand = cmd; da.Fill(ds); viewdatagrid.DataSource = ds.Tables[0]; Database.CloseConnection(); int height = 0; foreach (DataGridViewRow row in viewdatagrid.Rows) { height += row.Height; } height += viewdatagrid.ColumnHeadersHeight; int width = 0; foreach (DataGridViewColumn col in viewdatagrid.Columns) { width += col.Width; } width += viewdatagrid.RowHeadersWidth; viewdatagrid.ClientSize = new Size(width + 2, height + 2); } catch (Exception ex) { MessageBox.Show(ex.Message); } } </code></pre> <p>Please tell me how can I do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload