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
mahesh waghela
NA
93
114.1k
Draw Line To Listview Control
Aug 19 2011 1:47 PM
I am trying here to draw a line to listview control but fails to do so. my complete demonstration is below:
public partial class Form1 : Form
{
private ListView mylst;
public Form1()
{
InitializeComponent();
MyListView1 lst = new MyListView1();
mylst = lst;
this.Controls.Add(mylst);
}
private void Form1_Load(object sender, EventArgs e)
{
mylst.Dock = DockStyle.Fill;
listviewbind();
}
public class MyListView1 : ListView
{
protected override void OnPaint(PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black, 3);
// Create points that define line.
Point point1 = new Point(0, 0);
Point point2 = new Point(10, 0);
// Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2);
base.OnPaint(e);
}
}
public void listviewbind()
{
mylst.View = View.Details;
mylst.Columns.Add("name");
mylst.Columns.Add("amount");
string connstr = "server=.;initial catalog=maa;uid=mah;pwd=mah";
SqlConnection con = new SqlConnection(connstr);
con.Open();
string sql = "select name,amount from dummy";
SqlDataAdapter dap = new SqlDataAdapter(sql, con);
DataTable ds = new DataTable();
dap.Fill(ds);
for (int i = 0; i < ds.Rows.Count;i++)
{
DataRow dr = ds.Rows[i];
ListViewItem lvi = new ListViewItem(dr["name"].ToString());
lvi.SubItems.Add (dr["amount"].ToString());
mylst.Items.Add(lvi);
}
}
How to draw a line to a Listview Control?
Reply
Answers (
1
)
Trapping windows messages
C#.net code