Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid multiple row selection

Status
Not open for further replies.

michelleHEC

Programmer
Oct 20, 2003
95
US
I would like to highlight a group of rows and change all the values of one column to a value.
another words, when the user sees the datagrid, they may only want to select say 4 rows. while these 4 rows are selected, they will change all of the data in column "Status" to "S" without goint to each textbox,
can this be done? I have created a toolbox button that i would like to use once they have selected the rows they want to change. I am really stumped...
thank you
Michelle
 
you should be able to cycle through the rows in the grid and check the .IsSelected property of them.

I would again pimp the C1 Flexgrid and it's .rows.selected collection. Makes finding the highlighted rows real easy.

-Rick

----------------------
 
thanks that sound like what i need. do you have any code that does that. I tried to use the isSelected and i am not sure what you mean by C1 flex grid...
thanks again
michelle
 
the Component One flex grid is a flex grid. It is available on the Microsoft .Net Resource Kit, which I beleive can be downloaded from microsoft.com.

As for .IsSelected, it takes an integer parameter (the row number). so you'll have to create a loop the checks to see if each row number is selected.

-Rick

----------------------
 
ok, i have just begun to create a loop to put the count of what is selected into it. once i do that can i update a column for each selected item?
another words i need to put "C" in the Status column of the selected rows.
thank you so much for you help so far!
 
Code:
dim i as integer =0
try
  while true
    i+=1
    if datagrid.isselected(i) then
      'something about "C"
    end if
  end while
catch
end try

Not the prettiest, but it should go through all of the rows in the data grid and give you the index of those that are highlighted.

-Rick

----------------------
 
thank you rick for your help. I still had a problem with getting the right selection and updating the database. I am sure it is my error but here is what I did as a solution.
If e.Button.Tag = "restore" Then
Dim intCount As Integer
Dim drChange As DataRow
Dim status As String = "R"
Dim account As String
intcount = Me.Current_Outages1.OUTAGE_CALLS.Rows.Count - 1
Dim i As Integer = 0
For i = 0 To intcount
If DataGrid1.IsSelected(i) Then
Dim currentRow As DataRow = Current_Outages1.Tables("outage_calls").Rows(i)
currentRow("status") = status
currentRow("status_time") = Now
End If
Next
End If
'this puts the dataset
dsModifiedRows = Me.Current_Outages1.GetChanges(DataRowState.Modified)
If Not dsModifiedRows Is Nothing Then
Me.OleDbDataAdapter1.Update(dsModifiedRows)
End If
Me.Current_Outages1.AcceptChanges()
Me.Current_Outages1.Clear()
OleDbDataAdapter1.Fill(Me.Current_Outages1)

there was a problem with updating on a (0), but this worked. I hope this helps someone else. I don't know what I would do without Tek-Tips!
Michelle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top