Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everybady,

I want to create a table in c#. But Please read my problem carefully.

I have table in MSsql with 2 column
column1- as CustomerId
column2 as Drawtime

In C# Windows Applcation i get the complete data from this table.

My Data in DataTable display like this.

CustomerId | DrawTime
1 09:00
2 09:15
3 09:30

Now I want to display on Form using c# like this


|1 | 09:00 | 2 | 09:15 | 3 | 09:30 | 4 | 09:45 | 5 | 10:00 |
|6 | 10:15 | 7 | 10:30 | 8 | 10:45 | 9 | 11:00 | 10 | 11:15 |

Who to display record in table like this. Please help me guide
me.


I do not understand how to display record like this.
I am using datagridview but it is not possible in this control.

thanks
Ram Kumar
Posted

Another alternative is to use a System.Windows.Forms.ListView changing the View property to SmallIcon.

Format your table results and add them to the listview e.g.
this.listView1.Items.Add(new ListViewItem(Text = string.Format("|{0}|{1}", CustomerId, DrawTime)));

Choose an appropriate width for the control so that 5 "icons" are displayed
 
Share this answer
 
Comments
DamithSL 22-Oct-14 8:49am    
yes, ListView will be more appropriate for this task.5wd!
BillWoodruff 22-Oct-14 10:22am    
+5
You should use DataList control to display records as row wise-

Refer -

http://msdn.microsoft.com/en-us/library/bb525467.aspx
 
Share this answer
 
Comments
Ram Kumar(Webunitech) 22-Oct-14 4:55am    
Dear Sir,

I am working in C# windows Application not in Asp.net
I thought of a possible solution iterating through your datatable, every group of 5 (CustomerID/DrawTable) pairs creates one row.. the logic's a bit rough though (fairly standard principle, convert an linear 'index' or count to a subscript [row, column] pair)

Do you want me to post more ? (or have you found an answer ?)
 
Share this answer
 
Comments
Ram Kumar(Webunitech) 23-Oct-14 2:52am    
Dear Sir,
Please post more and give me better solutions.
sorry Ram, didn't see your reply

I was thinking of this (very roughly)

C#
int prev_row = -1;
int iteration_count = -1;
int this_col = 0;

foreach(DataRow row in MyDataTable)
{
    iteration_count += 1;
    this_row = iteration_count / 5;     // Integer Division

    this_col = iteration_count % 5;     // Modular Arithmetic

    // but we need to map 5 cols to 10
    // so 0 -> 0,1
    //    1 -> 2,3
    //  ..4 -? 8.9

    int this_col1 = 2*this_col;         // Stores 1,2,3,4, interleaved with 
    int this_col2 = (2 * this_col) + 1; // 9:00, 9:15...

    // Maybe use a String[10] ColumnArray to hold the columns as the are built 
    // Build Column Here

    // Check If Row Complete
    if (this_row != prev_row)
    {
        // Add The DataGridRow

        // Clear the ColumnArray[] if we used it 

        // Switch the row markers
        prev_row = this_row;
    }

}


to start with, and blending it with something like

C#
myDataGridView.Rows.Add() ;
 int RowIndex = myDataGridView.RowCount - 1;
 DataGridViewRow R= myDataGridView.Rows[RowIndex];
 R.Cells[0].Value = columnArray[0];
 R.Cells[1].Value = columnArray[1];
 ...
 
Share this answer
 
What you need is not a table, but series of labels. Even in your example, the lines aren't aligned. If you want them aligned use Courier New or other fixed width font and you'll have the solution.

So, go through your DataTable rows and either add labels for each element or just concatenate string and show it all in one big label. With some formatting you'll get what you want.

Alternative, of course, is to create your own DataTable and convert your original table to this new one. Then you set new one as your grids DataSource - with some formatting, you'll get the borders as above.

If this solution helps, please take time to accept it. Thank you.
 
Share this answer
 
v2

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