Someone has to have done this. User clicks on a heading and sorts the datagrid by a column, and a marker appears next to the column header showing the sort. Just like Access, Just like Outlook. Ya know.
My users want everything. This should not be so hard.
No, because I don't know how to return the column that the the user clicked on...
That's my problem. What stinking column did he click on. Sorry, but I look in all the documentation (that stinks, and is written for C programmers).
Getting frustrated with this grid. There must be some good documentation somewhere. Read 4guys from rolla. I never liked MS's descriptions. They are written by geeks.
No, they are not auto generated. The first 4 columns are:
Edit button, Delete button, Show details button, sequence number hidden. Then it starts with CustNum, CustName1, Address1,....
Any and all help would be much needed. Thank you so much!
Sub dgAgwayCust_Page(ByVal Sender As Object, ByVal E As DataGridPageChangedEventArgs)
' display a new page of data
dgAgwayCust.EditItemIndex = -1
dgAgwayCust.CurrentPageIndex = E.NewPageIndex
BindCustGrid(strCustGridSort)
BindCallGrid()
End Sub
Sub dgAgwayCust_SortEventHandler(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs)
strCustGridSort = e.SortExpression & " ASC"
BindCustGrid(strCustGridSort)
'Dim dgHeader As DataGridItem
'dgHeader = e.CommandSource
'TextBox1.Text = dgAgwayCust.Columns(dgAgwayCust.SelectedIndex).HeaderText
'TextBox1.Text = dgAgwayCust.SelectedItemStyle.BackColor.ToString
'dgAgwayCust.SelectedItemStyle.
End Sub
Disregard the remarks. I was trying to find the header.
'Define the connection object
Dim objConnection As New SqlConnection(strConnection)
Dim objDataAdapter As New SqlDataAdapter(strSQLCommand, objConnection)
'Define the DataSet
Dim dsCust As New DataSet
'Fill the DataSet with the database data
objDataAdapter.Fill(dsCust)
'Not needed
'objConnection.Close()
'Bind the DataGrid to the DataSet
dgAgwayCust.DataSource = dsCust
dgAgwayCust.DataBind()
dgAgwayCust.DataKeyField = "SeqNo"
What I'm wondering is this...
You seem to be able to relate e.SortExpression back to your SQL to fill your DataTable, and you can iterate through the columns of a DataTable. Are the DataTable columns all bound to DataGrid columns, and if so are they bound sequentially?
Basically, if you ignore your Button columns, is the dataGrid the same as the DataTable?
Can you use the command window to find what e.SortExpression equals.
If, as I suspect, it's the same as the equivalent column name in the DataTable, can't you iterate through the columns in the source datatable, get the column index of the column which is the datasource for the column your sorting by, by matching the column name against the value of e.SortExpression, add to it the number of ButtonColumns preceding your Bound columns in the DataGrid and ssubsequently get the index of the bound column you're interested in?
Sounds long winded, and as I'm now at home I can't play with this for you on my .net machine to get the code unfortunately, but something along these lines may get the info you want, as when you get the index of your DataGrid column you're set up to be able to use DataGrid.Columns[Index].HeaderImageUrl...
If you can wait till tomorrow, I'll get some syntax together for you, but I have to get off now. If you give it a go, let me know how you get on, I'm quite interested in this, it might be useful...
jn03, The problems not sorting the datagrid but providing an up or down arrow image in the header of the column the grids sorted by, with the arroe in the appropriate direction of course...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.