Click here to Skip to main content
16,015,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all members,
I want to Bind DatagridView from database just like my Attachment designed
in Windows Application. C#.
How???? (not manual).
Please Help.

i am using that code.
C#
private void binddata()
{
SqlDataAdapter da = new SqlDataAdapter(@"SELECT distinct Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' + Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks
as 'Groupst', Question,Fullmarks FROM dbo.tbl_QuestionConfig where Subject='C++'
group by Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' +
Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks ,Question,Fullmarks", con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;

dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightSeaGreen;
foreach (DataGridViewRow r in dataGridView1.Rows)
{
r.DefaultCellStyle.BackColor = Color.LightCyan;
}


} 



Click here

Please See the link.
i tried but couldn't.

What I have tried:

Posted
Updated 22-Aug-16 23:39pm
v4

C#
dataGridView1.AutoGenerateColumns = false;

Here is your problem If you have not dataGridView1 in your Form designed with the columns as your datatabe returns at compile time.If so change this line as
C#
dataGridView1.AutoGenerateColumns = true;
 
Share this answer
 
Comments
Riya Roy 23-Aug-16 1:20am    
please see the link first. i want that kind of design in windows application C#.
Anisuzzaman Sumon 23-Aug-16 1:26am    
sorry I have missed to see the link before answering .Ok I will improve my solution
Riya Roy 23-Aug-16 1:29am    
see the link https://postimg.org/image/55zvylwpn/
Anisuzzaman Sumon 23-Aug-16 2:27am    
As you are trying to do actually not any default control to do so in windows Application..There are many third parties who provides such type of controls.In web App easily you can achieve this using Repeater.
However I like to make a custom solution if you are not interested to use third party.To accomplish this I need to have the table definitions along with some sample data.If possible then provide me I will make a ready tea for you? :)
Riya Roy 23-Aug-16 3:03am    
what is third party control? give me code.

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