what is the next step, i have the code but i dont know what to do next?










-1















im new to c# and i'm trying to fill my datagridview with data from the database and make a groupby on certain column.



for ex:



i have a datagridview that contains : field, fullname and worker_id.



i want to get the data from database and group them according to the field name.



public void FillFullSchedule()



using (SqlConnection sqlcon = new SqlConnection(con))

sqlcon.Open();
SqlCommand cmd = new SqlCommand("dbo.FullScheduleData", sqlcon);
//SqlDataReader reader = cmd.ExecuteReader();

SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
fullScheduleDG.Rows.Clear();
foreach (DataRow dr in dt.Rows)

int n = fullScheduleDG.Rows.Add();
fullScheduleDG.Rows[n].Cells[0].Value = dr[1].ToString();
fullScheduleDG.Rows[n].Cells[1].Value = dr[0].ToString();
fullScheduleDG.Rows[n].Cells[2].Value = dr[2].ToString();








no problem with that.



i have the code for grouping the data from this post:



https://stackoverflow.com/a/44807088/10534001



but i dont know how to use it. what should i do ?? i dont know the next step.



is it to add events to cellformating or something like that or what ?










share|improve this question






















  • Take a look at the following thread: stackoverflow.com/questions/19114635/…

    – Access Denied
    Nov 13 '18 at 3:33






  • 2





    Don't fill grid, but simply bind it.

    – Access Denied
    Nov 13 '18 at 3:34











  • fullScheduleDG .DataSource = dt, will be same result as you doing it manually in the loop.

    – Fabio
    Nov 13 '18 at 3:35











  • Use grouped datasource or inherited datagridview instead of datagridview. In Initilize method replace new DataGridView with new GroupByGrid.

    – Access Denied
    Nov 13 '18 at 3:35












  • Don't bind grid to DataTable but rather to DataView. You can sort, search using data view. DataTable should be just a storage, view should be source

    – T.S.
    Nov 13 '18 at 3:48















-1















im new to c# and i'm trying to fill my datagridview with data from the database and make a groupby on certain column.



for ex:



i have a datagridview that contains : field, fullname and worker_id.



i want to get the data from database and group them according to the field name.



public void FillFullSchedule()



using (SqlConnection sqlcon = new SqlConnection(con))

sqlcon.Open();
SqlCommand cmd = new SqlCommand("dbo.FullScheduleData", sqlcon);
//SqlDataReader reader = cmd.ExecuteReader();

SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
fullScheduleDG.Rows.Clear();
foreach (DataRow dr in dt.Rows)

int n = fullScheduleDG.Rows.Add();
fullScheduleDG.Rows[n].Cells[0].Value = dr[1].ToString();
fullScheduleDG.Rows[n].Cells[1].Value = dr[0].ToString();
fullScheduleDG.Rows[n].Cells[2].Value = dr[2].ToString();








no problem with that.



i have the code for grouping the data from this post:



https://stackoverflow.com/a/44807088/10534001



but i dont know how to use it. what should i do ?? i dont know the next step.



is it to add events to cellformating or something like that or what ?










share|improve this question






















  • Take a look at the following thread: stackoverflow.com/questions/19114635/…

    – Access Denied
    Nov 13 '18 at 3:33






  • 2





    Don't fill grid, but simply bind it.

    – Access Denied
    Nov 13 '18 at 3:34











  • fullScheduleDG .DataSource = dt, will be same result as you doing it manually in the loop.

    – Fabio
    Nov 13 '18 at 3:35











  • Use grouped datasource or inherited datagridview instead of datagridview. In Initilize method replace new DataGridView with new GroupByGrid.

    – Access Denied
    Nov 13 '18 at 3:35












  • Don't bind grid to DataTable but rather to DataView. You can sort, search using data view. DataTable should be just a storage, view should be source

    – T.S.
    Nov 13 '18 at 3:48













-1












-1








-1








im new to c# and i'm trying to fill my datagridview with data from the database and make a groupby on certain column.



for ex:



i have a datagridview that contains : field, fullname and worker_id.



i want to get the data from database and group them according to the field name.



public void FillFullSchedule()



using (SqlConnection sqlcon = new SqlConnection(con))

sqlcon.Open();
SqlCommand cmd = new SqlCommand("dbo.FullScheduleData", sqlcon);
//SqlDataReader reader = cmd.ExecuteReader();

SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
fullScheduleDG.Rows.Clear();
foreach (DataRow dr in dt.Rows)

int n = fullScheduleDG.Rows.Add();
fullScheduleDG.Rows[n].Cells[0].Value = dr[1].ToString();
fullScheduleDG.Rows[n].Cells[1].Value = dr[0].ToString();
fullScheduleDG.Rows[n].Cells[2].Value = dr[2].ToString();








no problem with that.



i have the code for grouping the data from this post:



https://stackoverflow.com/a/44807088/10534001



but i dont know how to use it. what should i do ?? i dont know the next step.



is it to add events to cellformating or something like that or what ?










share|improve this question














im new to c# and i'm trying to fill my datagridview with data from the database and make a groupby on certain column.



for ex:



i have a datagridview that contains : field, fullname and worker_id.



i want to get the data from database and group them according to the field name.



public void FillFullSchedule()



using (SqlConnection sqlcon = new SqlConnection(con))

sqlcon.Open();
SqlCommand cmd = new SqlCommand("dbo.FullScheduleData", sqlcon);
//SqlDataReader reader = cmd.ExecuteReader();

SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
fullScheduleDG.Rows.Clear();
foreach (DataRow dr in dt.Rows)

int n = fullScheduleDG.Rows.Add();
fullScheduleDG.Rows[n].Cells[0].Value = dr[1].ToString();
fullScheduleDG.Rows[n].Cells[1].Value = dr[0].ToString();
fullScheduleDG.Rows[n].Cells[2].Value = dr[2].ToString();








no problem with that.



i have the code for grouping the data from this post:



https://stackoverflow.com/a/44807088/10534001



but i dont know how to use it. what should i do ?? i dont know the next step.



is it to add events to cellformating or something like that or what ?







c#






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 3:13









hussein mansourhussein mansour

86




86












  • Take a look at the following thread: stackoverflow.com/questions/19114635/…

    – Access Denied
    Nov 13 '18 at 3:33






  • 2





    Don't fill grid, but simply bind it.

    – Access Denied
    Nov 13 '18 at 3:34











  • fullScheduleDG .DataSource = dt, will be same result as you doing it manually in the loop.

    – Fabio
    Nov 13 '18 at 3:35











  • Use grouped datasource or inherited datagridview instead of datagridview. In Initilize method replace new DataGridView with new GroupByGrid.

    – Access Denied
    Nov 13 '18 at 3:35












  • Don't bind grid to DataTable but rather to DataView. You can sort, search using data view. DataTable should be just a storage, view should be source

    – T.S.
    Nov 13 '18 at 3:48

















  • Take a look at the following thread: stackoverflow.com/questions/19114635/…

    – Access Denied
    Nov 13 '18 at 3:33






  • 2





    Don't fill grid, but simply bind it.

    – Access Denied
    Nov 13 '18 at 3:34











  • fullScheduleDG .DataSource = dt, will be same result as you doing it manually in the loop.

    – Fabio
    Nov 13 '18 at 3:35











  • Use grouped datasource or inherited datagridview instead of datagridview. In Initilize method replace new DataGridView with new GroupByGrid.

    – Access Denied
    Nov 13 '18 at 3:35












  • Don't bind grid to DataTable but rather to DataView. You can sort, search using data view. DataTable should be just a storage, view should be source

    – T.S.
    Nov 13 '18 at 3:48
















Take a look at the following thread: stackoverflow.com/questions/19114635/…

– Access Denied
Nov 13 '18 at 3:33





Take a look at the following thread: stackoverflow.com/questions/19114635/…

– Access Denied
Nov 13 '18 at 3:33




2




2





Don't fill grid, but simply bind it.

– Access Denied
Nov 13 '18 at 3:34





Don't fill grid, but simply bind it.

– Access Denied
Nov 13 '18 at 3:34













fullScheduleDG .DataSource = dt, will be same result as you doing it manually in the loop.

– Fabio
Nov 13 '18 at 3:35





fullScheduleDG .DataSource = dt, will be same result as you doing it manually in the loop.

– Fabio
Nov 13 '18 at 3:35













Use grouped datasource or inherited datagridview instead of datagridview. In Initilize method replace new DataGridView with new GroupByGrid.

– Access Denied
Nov 13 '18 at 3:35






Use grouped datasource or inherited datagridview instead of datagridview. In Initilize method replace new DataGridView with new GroupByGrid.

– Access Denied
Nov 13 '18 at 3:35














Don't bind grid to DataTable but rather to DataView. You can sort, search using data view. DataTable should be just a storage, view should be source

– T.S.
Nov 13 '18 at 3:48





Don't bind grid to DataTable but rather to DataView. You can sort, search using data view. DataTable should be just a storage, view should be source

– T.S.
Nov 13 '18 at 3:48












1 Answer
1






active

oldest

votes


















0














Build a class with your 3 desired fields and a BindingList for the data to populate within the DataGrid.



public class yourClassName

public string field get; set;
public string fullname get; set;
public int worker_id get; set;

public class yourMainClass

public BindingList<yourClassName> yourDataForGrid get;
public yourMainClass(//this is a constructor. your params go here)

yourDataForGrid = GetDataForGrid(//your params here)




In your load method, create a new object and bind the fields:



yourClassName tempThing;
dgNameOfYourDataGrid.DataSource = new BindingSource(tempThing.yourDataForGrid, null);


Create the method that I called in the constructor that loads the BindingList:



 public static BindingList<yourClassName> GetDataForGrid(//your params here)

BindingList<yourClassName> tempList = new BindingList<yourClassName>();

//your sql code to build a dataset goes here
//foreach row in your dataset

yourClassName row = new yourClassName();
row.field = //insert value for field
row.fullname = //insert value for fullname
row.worker_id = //insert value for worker_id

tempList.Add(row);







share|improve this answer























  • Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

    – hussein mansour
    Nov 13 '18 at 23:52










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273247%2fwhat-is-the-next-step-i-have-the-code-but-i-dont-know-what-to-do-next%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Build a class with your 3 desired fields and a BindingList for the data to populate within the DataGrid.



public class yourClassName

public string field get; set;
public string fullname get; set;
public int worker_id get; set;

public class yourMainClass

public BindingList<yourClassName> yourDataForGrid get;
public yourMainClass(//this is a constructor. your params go here)

yourDataForGrid = GetDataForGrid(//your params here)




In your load method, create a new object and bind the fields:



yourClassName tempThing;
dgNameOfYourDataGrid.DataSource = new BindingSource(tempThing.yourDataForGrid, null);


Create the method that I called in the constructor that loads the BindingList:



 public static BindingList<yourClassName> GetDataForGrid(//your params here)

BindingList<yourClassName> tempList = new BindingList<yourClassName>();

//your sql code to build a dataset goes here
//foreach row in your dataset

yourClassName row = new yourClassName();
row.field = //insert value for field
row.fullname = //insert value for fullname
row.worker_id = //insert value for worker_id

tempList.Add(row);







share|improve this answer























  • Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

    – hussein mansour
    Nov 13 '18 at 23:52















0














Build a class with your 3 desired fields and a BindingList for the data to populate within the DataGrid.



public class yourClassName

public string field get; set;
public string fullname get; set;
public int worker_id get; set;

public class yourMainClass

public BindingList<yourClassName> yourDataForGrid get;
public yourMainClass(//this is a constructor. your params go here)

yourDataForGrid = GetDataForGrid(//your params here)




In your load method, create a new object and bind the fields:



yourClassName tempThing;
dgNameOfYourDataGrid.DataSource = new BindingSource(tempThing.yourDataForGrid, null);


Create the method that I called in the constructor that loads the BindingList:



 public static BindingList<yourClassName> GetDataForGrid(//your params here)

BindingList<yourClassName> tempList = new BindingList<yourClassName>();

//your sql code to build a dataset goes here
//foreach row in your dataset

yourClassName row = new yourClassName();
row.field = //insert value for field
row.fullname = //insert value for fullname
row.worker_id = //insert value for worker_id

tempList.Add(row);







share|improve this answer























  • Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

    – hussein mansour
    Nov 13 '18 at 23:52













0












0








0







Build a class with your 3 desired fields and a BindingList for the data to populate within the DataGrid.



public class yourClassName

public string field get; set;
public string fullname get; set;
public int worker_id get; set;

public class yourMainClass

public BindingList<yourClassName> yourDataForGrid get;
public yourMainClass(//this is a constructor. your params go here)

yourDataForGrid = GetDataForGrid(//your params here)




In your load method, create a new object and bind the fields:



yourClassName tempThing;
dgNameOfYourDataGrid.DataSource = new BindingSource(tempThing.yourDataForGrid, null);


Create the method that I called in the constructor that loads the BindingList:



 public static BindingList<yourClassName> GetDataForGrid(//your params here)

BindingList<yourClassName> tempList = new BindingList<yourClassName>();

//your sql code to build a dataset goes here
//foreach row in your dataset

yourClassName row = new yourClassName();
row.field = //insert value for field
row.fullname = //insert value for fullname
row.worker_id = //insert value for worker_id

tempList.Add(row);







share|improve this answer













Build a class with your 3 desired fields and a BindingList for the data to populate within the DataGrid.



public class yourClassName

public string field get; set;
public string fullname get; set;
public int worker_id get; set;

public class yourMainClass

public BindingList<yourClassName> yourDataForGrid get;
public yourMainClass(//this is a constructor. your params go here)

yourDataForGrid = GetDataForGrid(//your params here)




In your load method, create a new object and bind the fields:



yourClassName tempThing;
dgNameOfYourDataGrid.DataSource = new BindingSource(tempThing.yourDataForGrid, null);


Create the method that I called in the constructor that loads the BindingList:



 public static BindingList<yourClassName> GetDataForGrid(//your params here)

BindingList<yourClassName> tempList = new BindingList<yourClassName>();

//your sql code to build a dataset goes here
//foreach row in your dataset

yourClassName row = new yourClassName();
row.field = //insert value for field
row.fullname = //insert value for fullname
row.worker_id = //insert value for worker_id

tempList.Add(row);








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 16:48









noelnoel

316




316












  • Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

    – hussein mansour
    Nov 13 '18 at 23:52

















  • Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

    – hussein mansour
    Nov 13 '18 at 23:52
















Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

– hussein mansour
Nov 13 '18 at 23:52





Ok till now you told me how to do all that above but where should i use the code in this link : stackoverflow.com/a/44807088/10534001 for merging the cells of the datagrid? If you check that link you will find exactly what I need but the thing is that i dont know how to do it step by step

– hussein mansour
Nov 13 '18 at 23:52

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273247%2fwhat-is-the-next-step-i-have-the-code-but-i-dont-know-what-to-do-next%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto