Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Column 1

A
B
C
D
E
F
G
H
I
K
L
M
N

I am able to get the details as like above format. But i want to show my output in below format.Please help.

Column 1

A B C D E F G

H I J K L M N
Posted
Comments
Maciej Los 13-May-14 13:18pm    
Based on what condition?
Kamal Kannan 14-May-14 0:06am    
Using datatable For example: DataTable Obj_DT= new DataTable();<br>
Obj_DT.Columns.Add("Column 1");<br>
i am getting the column values in vertically. But i want to get the values of a single column in multiple cells horizontally.
Maciej Los 14-May-14 11:49am    
:laugh: I'm not asking you: how? i'm asking you: based on what condition?
Kamal Kannan 14-May-14 12:38pm    
I am using (if, else) condition and for loop to view vertically. Same i need to view the values splitted in horizontal view.

1 solution

Hi,

I am not sure I understand your requirement correctly..
I think we cannot get this result through data binding..
Hope a for loop will do..

Try this.
VB
Dim RowCounter As Integer = 0
Dim ColCounter As Integer = 0
Dim Counter As Integer = 0

DGV1.Rows.Clear()
DGV1.Rows.Add()
For Counter = 0 To DT.Rows.Count - 1
    DGV1.Item(ColCounter, RowCounter).Value = DT.Rows(Counter).Item(0).ToString()
    ColCounter += 1
    If DGV1.ColumnCount = ColCounter Then
        DGV1.Rows.Add()
        RowCounter += 1
        ColCounter = 0
    End If
Next Counter


Regards,
Saravanakumar. N
 
Share this answer
 
Comments
Kamal Kannan 14-May-14 12:34pm    
int RowCounter = 0;
int ColCounter = 0;
int Counter = 0;
DataTable DT = new DataTable();

dgSwitchview.Rows.Clear();
dgSwitchview.Rows.Add();
for (Counter = 0; Counter <= DT.Rows.Count - 1; Counter++)
{
dgSwitchview.Item(ColCounter, RowCounter).Value = DT.Rows(Counter).Item(0).ToString()

//dgSwitchview.Rows.Add(ColCounter, RowCounter).ToString() = DT.Rows.Count.ToString();

ColCounter += 1;
if (dgSwitchview.ColumnCount == ColCounter)
{
dgSwitchview.Rows.Add();
RowCounter += 1;
ColCounter = 0;
}
}

I have converted your code to c#. I am getting error on executing this code.
vbn.saravanakumar 15-May-14 4:31am    
Hi..<br>
 <br>
Let me know the exact error message you got..<br>
Please make sure that, <br>
- you have enough number of columns in the data grid view (as per your requirement I have added 7 columns in the dgv). <br>
- you have data in the data table. <br>
- the dgv is not a data bound one.

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