I'm trying to select the item in the Combobox based on the stored value in a Sorteddictionary
String value matching
comboBoxEdit3.SelectedItem = comboBoxEdit3.FindStringExact(Queries[_ucSetting.StandardSearchID.ToString()] + "(" + _ucSetting.StandardSearchID.ToString() + ")");
Elements in ComboBox
But this produces empty selection in the ComboBox
FindStringExact only returns the index of the first item that matches your string, or -1 if no match is found. You're trying to set the SelectedItem to the index being returned. You should set the SelectedIndex instead:
comboBoxEdit3.SelectedIndex = comboBoxEdit3.FindStringExact(Queries[_ucSetting.StandardSearchID.ToString()] + "(" + _ucSetting.StandardSearchID.ToString() + ")");
Related
I have a DataGrid that is generated from a MySQL query. I would like to to be able to edit the database directly by modifying the DataGrid. Basically what I need is to generate a string like this after user has finished editing a cell:
pseudocode:
"UPDATE current_table SET current_column_name=new_cell_value WHERE id=number that is in the hidden first cell of the edited row"
What would be the most simple way to achieve this?
I've tried looking at the DataGrid properties and events but so far I could not find any "CellEditEnded" events nor can I find how to get the new value or the id that's in the first cell of the row.
EDIT:
Ok, I've made some progress, I am now able to get the id and the column name, but the problem is that I am unable to get the new cell value. I think the problem is that this code fires in CellEditEnding-event, so the change hasn't been commited yet. How can I fix this?
DataRowView dataRow = (DataRowView)gameDatagrid.SelectedItem;
int index = gameDatagrid.CurrentCell.Column.DisplayIndex;
string columnName = gameDatagrid.CurrentCell.Column.Header.ToString();
string cellValue = dataRow.Row.ItemArray[index].ToString();
string id = dataRow.Row.ItemArray[0].ToString();
MessageBox.Show(id + " : " + columnName + " : " + cellValue);
Thanks to a helpful comment I was able to solve this. The full code is as follows:
private void gameDatagrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
TextBox t = e.EditingElement as TextBox;
DataRowView dataRow = (DataRowView)gameDatagrid.SelectedItem;
int index = gameDatagrid.CurrentCell.Column.DisplayIndex;
string columnName = gameDatagrid.CurrentCell.Column.Header.ToString();
string newValue = t.Text;
int id = (int)dataRow.Row.ItemArray[0];
string query = "UPDATE table_name SET " + columnName + "=\"" + newValue + "\" WHERE id=" + id;
}
I have 2 Lookup edits in my winform. If I select 1st Lookup edit, need to add data source to 2nd Lookup edit based on what i selected in value in 1st Lookup edit. This all function can be done at run time.
This code i use currently for 1st Lookup edit and If i select any Item from 1st Lookup edit I need to fill / attach data source to 2nd Lookup edit.
How to complete my task ?
private void lookupedit1_EditValueChanged(object sender, EventArgs e)
{
object row = lookupedit1.Properties.GetDataSourceRowByKeyValue(lookupedit1.EditValue) as object;
memoedit1.Text = (row as DataRowView)["BFlatNo"].ToString() + ", " + (row as DataRowView)["BLocation"].ToString() + ".";
memoedit2.Text = (row as DataRowView)["DFlatNo"].ToString() + ", " + (row as DataRowView)["DLocation"].ToString() + ".";
}
Thanks in advance.
You can do this as follows:
yourLookUpEdit.Properties.DataSource = //Your List or DataTable
I have an ASP.NET gridview within which i have a template column which hosts a dropdown. the dropdown is bound from server side code. I am attaching the following JavaScript:
dl.Attributes.Add("onchange", "return UpdateTaskDetail(" + dl.ClientID + ",'" + u.TaskID + "','" + "');");
I am able to execute the JavaScript function name UpdateTaskDetail.
The issue in want to get the selected value of the dropdown for which i have been trying the following
var taskstatusid = $("#" + ctr.name + " option:selected").val();
This line does not fetch the value.
Can someone please tell me what might be incorrect?
In your UpdateTaskDetail function you can do something like this:
function UpdateTaskDetail(control, task, other ){
var taskstatusidVal = $("#" + control).val();//For selected value. remove "option:selected"
var taskstatusidText = $("#" + control + " option:selected").text();//For selected Text
alert(taskstatusidVal + taskstatusidText);//Test
}
Cenario:
I have a GridView bound to a DataSource, every column is sortable.
my main query is something like:
select a, b, c, d, e, f from table order by somedate desc
i added a filter form where i can define values to each one of the fields and get the results of a where form. As a result from this, i had to do a custom sorting so that when i sort by a field, i am sorting the filtered query and not the main one.
Now i have to do custom paging, for the same reason, but i don't understand the philosophy of it: I want to guarantee that i can:
filter the results
sort by a column
when i click on page 2, i get page two of the filtered and sorted results
I don't know what i have to do, so i can bind the GV with this. My sorting Method, that is working just fine looks something like:
string condition = GetConditions(); //gets a string like " where a>1 and b>2" depending on the filter the user defines
string query = "select a, b, c, d, e, f from table ";
string direction = (e.SortDirection == SortDirection.Ascending)? "asc": "desc";
string order = " order by " + e.SortExpression + " " + direction;
UtilizadoresDataSource.SelectCommand = query + condition + order;
i've never done custom paging, i am trying:
GetConditions() //no problem here
How can i find out how the GridView is sorted (by what field and sortingorder)?
thank you very much
You can use ROW_NUMBER to get the number of rows that a query is returning and then filter only those element that will be visible for the given page. For example you should add ROW_NUMBER function in the select clause and add the filtering in the where cause.
string condition = GetConditions(); //gets a string like " where a>1 and b>2" depending on the filter the user defines
string query = "select ROW_NUMBER() OVER(ORDER BY " + order + ") a, b, c, d, e, f from table ";
string direction = (e.SortDirection == SortDirection.Ascending)? "asc": "desc";
string order = " order by " + e.SortExpression + " " + direction;
condition = condition + " RowNo BETWEEN ((#Page - 1) * #PageSize + 1) AND (#Page * #PageSize) "
UtilizadoresDataSource.SelectCommand = query + condition + order;
You can find a more detailed example here.It also contains a sample project with binding a grid.
P.S. I would suggest you to create a stored procedure and pass the parameters from the code behind. This can increase the speed and also it easier to maintain.
Below code is written in such a way to retrieve all selected check box values
But its retieve only the first selected value
Please help
Dim CheckedValues As String
For Each item as ListItem In txt_panview0_ddinput1.Items
If item.Selected Then
CheckedValues = CheckedValues & item.Value
End If
Next
If Not String.IsNullOrEmpty(checkedValues) Then
checkedValues = checkedValues.Substring(1)
End If
tempCollector = tempCollector + "<br>" + "Area Name" + ": " + checkedValues
If I read your code correctly, you're mashing together all of the values from your list into a string, without anything separating them. You therefore have no way of retrieving the original values.
You could try separating your values with a comma before adding them to the string. But there might be a better way to do this. It really depends on what you are trying to do. You might have better luck filling a list object.
Changed CheckedValues = CheckedValues & item.Value
to
CheckedValues += CheckedValues & item.Value perhaps