vellaima Posted February 22, 2003 Posted February 22, 2003 Dim myReader As System.Data.OleDb.OleDbDataReader myReader = SelectData.ExecuteReader() While myReader.Read() str(0) = myReader.GetString(0) str(1) = myReader.GetString(1) itm = New ListViewItem(str) itm.Checked = True ---> error?? ListView1.Items.Add(itm) In the above code if i write itm.checked=true during runtime i get error. If i ignore the error the item is indeed getting checked. If the itm.checked=false, i am not getting run time error. The runtime error i am getting is "Object reference not set to the instance of the object". Can you please tell me why such error is occuring. Quote
vellaima Posted February 23, 2003 Author Posted February 23, 2003 Can anyone please help me out. I am desperate. Quote
vellaima Posted February 23, 2003 Author Posted February 23, 2003 ListView is making my life hell Dim str(2) as String Private Sub test_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ListView_AddCol() ListView_AddData() End Sub Private Sub ListView_AddCol() ListView1.Columns.Add("Item ID", 110, HorizontalAlignment.Left) ListView1.Columns.Add("Item Desc", 170, HorizontalAlignment.Left) End Sub Private Sub ListView_AddData() str(0) = "Item 1" str(1) = "ABC" Dim itm as New ListViewItem itm.Checked = True ListView1.Items.Add(itm) End Sub Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck Dim ij1 as Integer ij1 = e.Index If ListView1.Items(ij1).Checked = True Then ListView1.Items(ij1).Checked = False End If End Sub I am getting run time error when there is ItemCheck Sub and when i set a particular item is set to true during loading. If there is no itemCheck sub it is working fine Can anyone please help me as to why such error is occuring since i am new to programming. Quote
*Gurus* divil Posted February 23, 2003 *Gurus* Posted February 23, 2003 itm.Checked = True That line itself should not cause an error. I am skeptical that it does. If indeed it does, make a sample application that reproduces the error and send it to Microsoft. Or, just post your whole project here (without binaries) and I'll see what I can do. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
hellojunk007 Posted February 23, 2003 Posted February 23, 2003 I tested your code and didn't get any run time error. It seemed to work fine. Can you give more details of the error you are getting. Also, can you briefly describe what you are trying to do. Quote
vellaima Posted February 23, 2003 Author Posted February 23, 2003 I want to do some validation depending upon whether the item is checked or unchecked. I think the ListView1_ItemCheck is getting triggered during runtime. Can it be avoided. Due to that i am getting errors. Quote
*Gurus* divil Posted February 23, 2003 *Gurus* Posted February 23, 2003 It's very possible that setting the checked property raises the ItemCheck event. If this is the case, you'll have to use a form-scoped boolean variable to tell the code in that event not to run if you're setting it manually. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
vellaima Posted February 23, 2003 Author Posted February 23, 2003 I am new to vb.net divil can you please provide me with a example. It will be very helpful. Quote
*Gurus* divil Posted February 23, 2003 *Gurus* Posted February 23, 2003 Well, you should have something like this to declare your variable and in the ItemCheck event: Private ignoreListviewChecks As Boolean Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck If ignoreListviewChecks Then Return 'Perform validation here End Sub And whenever you change a listitem's Checked property manually in code, surround the line by setting the variable to true: ignoreListviewChecks = True myListViewItem.Checked = True ignoreListviewChecks = False Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
vellaima Posted February 23, 2003 Author Posted February 23, 2003 Divil, can you please help me with this code. It will be very helpful. I have written the following sample code. Can you please modify it for me. It is getting triggered during run time. Dim ij as integer ij = e.Index() if ListView1.Items(ij).checked=True 'Do some validation else ' Do some validation end if. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.