Click here to Skip to main content
15,887,338 members
Home / Discussions / C#
   

C#

 
AnswerRe: ERP project - one project? Pin
Luc Pattyn15-May-11 4:11
sitebuilderLuc Pattyn15-May-11 4:11 
AnswerRe: ERP project - one project? Pin
Dan Mos15-May-11 3:48
Dan Mos15-May-11 3:48 
AnswerRe: ERP project - one project? Pin
Keith Barrow15-May-11 3:59
professionalKeith Barrow15-May-11 3:59 
AnswerRe: ERP project - one project? Pin
Pete O'Hanlon15-May-11 9:23
mvePete O'Hanlon15-May-11 9:23 
GeneralRe: ERP project - one project? Pin
walterhevedeich15-May-11 19:21
professionalwalterhevedeich15-May-11 19:21 
AnswerRe: ERP project - one project? Pin
Prasanta_Prince15-May-11 21:18
Prasanta_Prince15-May-11 21:18 
AnswerRe: ERP project - one project? Pin
SilimSayo16-May-11 5:23
SilimSayo16-May-11 5:23 
QuestionIs There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright14-May-11 20:32
professionalRoger Wright14-May-11 20:32 
I've spent the entire night trying to do one simple thing - populate a ListView from a DataTable and display it. That isn't asking so much, is it? From MSDN, I learned that I have to use Details view to display multiple columns containing subitems, so I tried that. In VS2010 the IDE claims that View.Details is not defined, though in Designer View I can set the View Property to Details. All examples in MSDN include the line: ListView1.View = View.Details but it doesn't exist in VS 2010. Having made the proper setting in Designer View, I set about creating something useful. Or so I thought.

What I'm trying to accomplish is to display a list of SQL Server instances on the network, and ask the user where to create a new database. Enumerating the available instances is easy, as the SqlSourceEnumerator.GetDataSources() method works great, returning a table with 4 columns of text. Using the DataTable.Columns.ColumnName() method does a nice job of populating the headers for my ListView, too. And adding ListItems and SubItems works fine, as well, as I can see the data being transferred when I step through the code using the debugger. But when it finally gets down to displaying the ListView, nothing is displayed but the headers! And even though I've set the AutoResizeColumns property to HeaderSize, they don't resize at all! My code follows, and any suggestions would be most welcome, especially if they involve sacrificing small animals - I'm in that sort of mood.

private void frmMain_Load(object sender, EventArgs e)
        {
            DataStuff MyData = new DataStuff();
            DataTable MyTable = MyData.GetSources();
            lvDataSources.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            lvDataSources.AutoResizeColumns((ColumnHeaderAutoResizeStyle.HeaderSize));
            //Populate Headers
            if (MyTable != null)
            {
                for (int i =0; i < MyTable.Columns.Count; i++)
                {
                    ColumnHeader hdr = new ColumnHeader();
                    hdr.Text = MyTable.Columns[i].ColumnName;
                    lvDataSources.Columns.Add(hdr);
                }
            //Populate Rows from MyTable                
            foreach (DataRow row in MyTable.Rows)
            {
                ListViewItem lvItem = new ListViewItem(row[0].ToString());
                for (int i =1;i < MyTable.Columns.Count;i++)
                {
                    if (row[i] != null)
                        lvItem.SubItems.Add(row[i].ToString());
                    else
                        lvItem.SubItems.Add("N/A");

                }
            }
            lvDataSources.Show();
            }
                
            
           

        }

Will Rogers never met me.

AnswerRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
dan!sh 14-May-11 21:01
professional dan!sh 14-May-11 21:01 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright15-May-11 4:26
professionalRoger Wright15-May-11 4:26 
AnswerRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
OriginalGriff14-May-11 21:06
mveOriginalGriff14-May-11 21:06 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
#realJSOP15-May-11 0:32
mve#realJSOP15-May-11 0:32 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Luc Pattyn15-May-11 2:34
sitebuilderLuc Pattyn15-May-11 2:34 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright15-May-11 4:39
professionalRoger Wright15-May-11 4:39 
GeneralRe: Is There An Incantation I'm supposed To Recite To Make The Data Appear? Pin
Roger Wright15-May-11 4:28
professionalRoger Wright15-May-11 4:28 
QuestionBeginner c# question Pin
SFORavi14-May-11 16:10
SFORavi14-May-11 16:10 
AnswerRe: Beginner c# question Pin
Luc Pattyn14-May-11 16:57
sitebuilderLuc Pattyn14-May-11 16:57 
GeneralRe: Beginner c# question Pin
SFORavi14-May-11 18:34
SFORavi14-May-11 18:34 
AnswerRe: Beginner c# question Pin
Luc Pattyn14-May-11 18:39
sitebuilderLuc Pattyn14-May-11 18:39 
GeneralRe: Beginner c# question Pin
Roger Wright14-May-11 20:11
professionalRoger Wright14-May-11 20:11 
GeneralRe: Beginner c# question Pin
Richard MacCutchan14-May-11 21:32
mveRichard MacCutchan14-May-11 21:32 
AnswerRe: Beginner c# question Pin
PIEBALDconsult14-May-11 18:52
mvePIEBALDconsult14-May-11 18:52 
GeneralRe: Beginner c# question Pin
jschell16-May-11 8:37
jschell16-May-11 8:37 
AnswerRe: Beginner c# question Pin
jschell16-May-11 8:39
jschell16-May-11 8:39 
Questionhow to disable and enable network access with simple c# code Pin
MohammedMahmoud14-May-11 10:41
MohammedMahmoud14-May-11 10:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.