TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vuk Stanojevic
1.6k
140
45k
C# listview header name=value from database
Apr 11 2020 11:16 AM
Hi Everyone,
I'm trying to create listview where column header name is retrieved from database (its number)
When i execute my code i get as column name System.Data.DataRow but it should be number from database.
My code is:
SqlConnection con =
new
SqlConnection(@
"Data Source=MAIN-PC\SQLEXPRESS;Integrated Security=True"
);
SqlCommand cmd =
new
SqlCommand(
"USE "
+comboBox1.Text+
" ; Select StoreCode FROM stores"
,con);
DataTable dt =
new
DataTable();
con.Open();
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
ListView view =
new
ListView();
view.View = View.Details;
listView1.Columns.Add(
"Store"
, 90, HorizontalAlignment.Left);
foreach
(DataRow row
in
dt.Rows)
{
listView1.Columns.Add(row.ToString(), 90, HorizontalAlignment.Left);
}
Result is:
Reply
Answers (
2
)
ComboBox Issue selectedIndexChanged
How to clear control that has children?