Dim userID As Integer = CType(ListBox1.SelectedItem, Int32)
24 Replies - 557 Views - Last Post: 01 March 2012 - 07:15 PM
#16
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 05:21 PM
Try using SelectedItem for Listbox
#17
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 05:41 PM
' Search for an existing row.
Dim rows As DataRow() = m_userRightTable.[Select]("right_id = " & rightID & " AND user_id = " & userID)
what is wrong with this code it doesnt seeem to want to work
#18
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 05:55 PM
What are you trying to archive here ?
I am assuming you are using a datagridview.How bout you loop through your datagridview.
I am assuming you are using a datagridview.How bout you loop through your datagridview.
Dim count As Integer = 0
Dim RowsFound As integer = 0
For Each Row As DataGridViewRow In DataGridView1.Rows
If DataGridView1.Rows(count).Cells("right_id").Value = rightID and
DataGridView1.Rows(count).Cells("user_id").Value = userID Then
'Do Something
RowsFound += 1
End If
count += 1
Next
Next Row
This post has been edited by shadachi: 01 March 2012 - 05:56 PM
#19
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 05:59 PM
no i am using a list view and what i am tryin to do is search for a existing row
i have 2 list views roles and user roles
when i click on a role i can assign it to many users
i have also made the rest of the code all together it looks like this
i have 2 list views roles and user roles
when i click on a role i can assign it to many users
i have also made the rest of the code all together it looks like this
Dim roleIndex As Integer = ListBox1.SelectedIndex
If (roleIndex = -1) Then
Return
End If
' Get the current user index.
Dim userIndex As Integer = ListBox2.SelectedIndex
' Should we ignore the the event?
If (userIndex = -1) Then
Return
End If
' Get the identifiers.
Dim userID As Integer = CType(ListBox1.SelectedItem, Int32)
Dim rightID As Integer = CType(ListBox2.SelectedItem, Int32)
' Search for an existing row.
Dim rows As DataRow() = ("Select right_id = " & rightID & " AND user_id = " & userID & "
' Is there already an association?
If (rows.Length > 0) Then
Return
End If
' Create a new association.
UserRightManager.Create(userID, rightID, false)
' Get the right for the user.
m_userRightTable = UserRightManager.FindByUser(userID).Tables(0)
' Bind the GUI to the table.
m_listBoxUserRights.DataSource = m_userRightTable
m_listBoxUserRights.DisplayMember = "right_name"
#20
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 06:21 PM
Right. Any problems with it?
#21
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 06:27 PM
' Search for an existing row.
Dim rows As DataRow() = ("Select right_id = " & rightID & " AND user_id = " & userID & ""
' Is there already an association?
If (rows.Length > 0) Then
Return
the error is at the end of the select statement
and also at the rows
#22
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 06:44 PM
Quote
And also at the rows
I think with the Return you must actually Return a value.
For instance, I have a function named IsExists and I sent a value for it to test:
Public Function IsExists(ByVal File As String) As Boolean If IO.File.Exists(File) Then Return True Else Return False End Function
With yours you are telling it to return something, but WHAT exactly?
A Boolean? An Integer? Is this code part of a function?
Quote
the error is at the end of the select statement
I don't know too much about DataRows but I don't think it accepts being set to a String:
Dim rows As DataRow() = ("Select right_id = " & rightID & " AND user_id = " & userID & ""
Perhaps you need to read more about the DataRow object. This site has a good example and is good reading material. It's from MSDN.
Quote
i have also made the rest of the code all together it looks like this
It's not a good idea just to splice chunks of code together from all sorts of sources without a detailed idea of what they accomplish.
#23
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 06:53 PM
Hmm.. I don't think that that portion of code would work ..
Based on the link below , which i presume is what you wanted to do right? Have a look .
http://msdn.microsof...y/det4aw50.aspx
Based on the link below , which i presume is what you wanted to do right? Have a look .
http://msdn.microsof...y/det4aw50.aspx
#24
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 06:59 PM
Forget about me, is this the right way to achieve what you want?
Oh no- I thought you were farhan_b!
Oh no- I thought you were farhan_b!
This post has been edited by DimitriV: 01 March 2012 - 07:01 PM
#25
Re: Intresting problem cannot solve :(
Posted 01 March 2012 - 07:15 PM
LoL.. DimitriV .. i too am confused about what he is trying to achieve and the way he wants it .
BTW farhan_b
Listviews and Listboxes are different things . Don't mix them up . =D
Well , another way of searching the listview is by looping i guess..i blurt this code on the spot so don't know whether it can work or not..
BTW farhan_b
Listviews and Listboxes are different things . Don't mix them up . =D
Quote
no i am using a list view and what i am tryin to do is search for a existing row
i have 2 list views roles and user roles
i have 2 list views roles and user roles
Well , another way of searching the listview is by looping i guess..i blurt this code on the spot so don't know whether it can work or not..
'' These two variables are the column index the two columns userid and rightid .
'' Assuming it is 0 for rightid and 1 for userid
Dim ColRightIDIndex as integer = 0
Dim ColUserIDIndex as integer = 1
For Each LvItem As ListViewItem In ListView1.Items
If LvItem.SubItems(ColRightIDIndex).Text = CStr(rightID) And LvItem.SubItems(ColUserIDIndex).Text = CStr(userID) Then
Return
End If
Next
|
|

New Topic/Question
Reply





MultiQuote


|