John (Yiannis) Toutountzoglou
asked on
ListBox Items As Header Text in a Datagridview Columns
I have a databound ListBox .I need to pass the items as header text in my datagridView Columns.
i use the follwing code
i use the follwing code
Dim drv as datarowview =Ctype(me.Listbox1.SelectedItem,Datarowview)
dim SelTex as String=drv.Item("ColumnItems")
Dim TNumber as integer =Me.Listbox.Items.Count
'For the Datagridview i set the visibility of the Desired Columns to true'
For i as integer =3 to (3+TNumber)-1
Me.Datagridview1.Columns.Item(i).Visible=true
Me.Datagridview1.Columns.item(i).HeaderText=SelText 'And Here Is My Problem I got Only the First item .I know that i have to loop through the lisbox items but......'
next
ASKER
Shahan_Dev…
that is why i 'am using drv as datarowview because with your code the header text goes to system.data.datarowview
that is why i 'am using drv as datarowview because with your code the header text goes to system.data.datarowview
Hi!
your this line was giving me the casting error:
Dim drv as datarowview =Ctype(me.Listbox1.Selecte dItem,Data rowview)
So I used my methodology to do the same but said it is not what you want.
change your line 8 with this and see what happened:
Me.Datagridview1.Columns(i ).HeaderTe xt=SelText
your this line was giving me the casting error:
Dim drv as datarowview =Ctype(me.Listbox1.Selecte
So I used my methodology to do the same but said it is not what you want.
change your line 8 with this and see what happened:
Me.Datagridview1.Columns(i
If you can post the datagridview's image before and after this code affected then it can help to trace the problem.
ASKER
I've done the way you told and i got the same results... Me.Datagridview1.Columns(i ).HeaderTe xt=Me.List Box1.Items (i).ToStri ng()
the header text of datagridviewColumns renamed and shows System.Data.DatarowView
the header text of datagridviewColumns renamed and shows System.Data.DatarowView
Hi!
I am unable to understand your problem. If you will show me your ListView values then I may be could do something, because I have a string in listview which is not convertable in DataRow view so it is giving error.
Also, what do you mean about :
>>> with your code the header text goes to system.data.datarowview
I am unable to understand your problem. If you will show me your ListView values then I may be could do something, because I have a string in listview which is not convertable in DataRow view so it is giving error.
Also, what do you mean about :
>>> with your code the header text goes to system.data.datarowview
ASKER
I think that i have to rephrase the Question ...
Let's say that you have a datagridview.
the Columns after Column(0) displays numbers that are Primary Keys or indexes of a table..(For example Table with 2 Columns Key and descrisption)
how can i replace these numbers with the description and put it as datagridview column header text..
Why am i doing this ...
Because using Greek Language when i am trying to set the column headers with the greek letters directly from datasource (Sql Database) the column headers shows "??????????"
So i am trying to find another way to solve this problem ....
Let's say that you have a datagridview.
the Columns after Column(0) displays numbers that are Primary Keys or indexes of a table..(For example Table with 2 Columns Key and descrisption)
how can i replace these numbers with the description and put it as datagridview column header text..
Why am i doing this ...
Because using Greek Language when i am trying to set the column headers with the greek letters directly from datasource (Sql Database) the column headers shows "??????????"
So i am trying to find another way to solve this problem ....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok that really helps....i got it and thank you very much...
Dim i As Integer = 0
For i = 0 To DataGridView1.Columns.Coun
'use one of these lines
DataGridView1.Columns(i).H
DataGridView1.Columns(i).H
Next