C# Programming
04-14-2009, 02:14 PM
The following code reads data from excel and displays it in the listview...I want the data displayed in the listview to scroll / move from bottom to top automatically !!!!!..........
hw can i do it ????.....Plz help !!!
**************************************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string Path = @"c:\gg.xls";
Excel.ApplicationClass app = new ApplicationClass();
Excel.Workbook workBook = app.Workbooks.Open(Path, 0, true, 5, Type.Missing, Type.Missing, true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;
object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
try
{
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
{
rowIndex = 2 + index;
string firstName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString();
string lastName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString();
listView1.Items.Add(firstName);
//listView1.Items.Add("\n");
listView1.Items.Add(lastName);
index++;
}
}
catch (Exception ex)
{
app.Quit();
}
}
}
}
************************************************************************************
hw can i do it ????.....Plz help !!!
**************************************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string Path = @"c:\gg.xls";
Excel.ApplicationClass app = new ApplicationClass();
Excel.Workbook workBook = app.Workbooks.Open(Path, 0, true, 5, Type.Missing, Type.Missing, true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;
object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
try
{
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
{
rowIndex = 2 + index;
string firstName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString();
string lastName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString();
listView1.Items.Add(firstName);
//listView1.Items.Add("\n");
listView1.Items.Add(lastName);
index++;
}
}
catch (Exception ex)
{
app.Quit();
}
}
}
}
************************************************************************************