How to bind ListView to Dataset

  • Thread starter Thread starter IfThenElse
  • Start date Start date
I

IfThenElse

Hi,

Is there an easy way now in 2005?
Need full example url etc..

Thank you,
 
Nicholas,

OH No, do it manually again, I am getting sick and tired of this.
Is there a better control with less work

Thanks by the way.


Nicholas Paldino said:
No, there is not. You still have to do it manually.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

IfThenElse said:
Hi,

Is there an easy way now in 2005?
Need full example url etc..

Thank you,
 
You should consider WPF then. It has a pretty good data binding model.
However, you might find it deficient in other areas.

You might be able to get away with hosting the WPF ListView control in
your Windows Forms app, but it seems like a lot of overhead.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

IfThenElse said:
Nicholas,

OH No, do it manually again, I am getting sick and tired of this.
Is there a better control with less work

Thanks by the way.


Nicholas Paldino said:
No, there is not. You still have to do it manually.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

IfThenElse said:
Hi,

Is there an easy way now in 2005?
Need full example url etc..

Thank you,
 
IfThenElse said:
Hi,

Is there an easy way now in 2005?
Need full example url etc..

populated, not bound ... but it IS easy:

private void fillListView(DataSet DS, ListView lv, string table)
{
DataTable dt = DS.Tables
;
int fc = dt.Columns.Count;

lv.Columns.Clear();
lv.Items.Clear();

for (int i = 0; i < fc; i++)
{
lv.Columns.Add("Column " + i.ToString());
}

foreach (DataRow row in dt.Rows)
{
string[] subitems = new string[fc];

object[] o = row.ItemArray;
for (int i = 0; i < fc; i++)
{
subitems = o.ToString();
}
ListViewItem item = new ListViewItem(subitems);
lv.Items.Add(item);
}

lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
 
Thanks Liz, I end up doing it the manual way: Defining my Columns one by
one etc..

Liz said:
IfThenElse said:
Hi,

Is there an easy way now in 2005?
Need full example url etc..

populated, not bound ... but it IS easy:

private void fillListView(DataSet DS, ListView lv, string table)
{
DataTable dt = DS.Tables
;
int fc = dt.Columns.Count;

lv.Columns.Clear();
lv.Items.Clear();

for (int i = 0; i < fc; i++)
{
lv.Columns.Add("Column " + i.ToString());
}

foreach (DataRow row in dt.Rows)
{
string[] subitems = new string[fc];

object[] o = row.ItemArray;
for (int i = 0; i < fc; i++)
{
subitems = o.ToString();
}
ListViewItem item = new ListViewItem(subitems);
lv.Items.Add(item);
}

lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top