I am binding a DataList with dynamic values (ie distances from google api From a particular location.)
ie from x location :
10 km away
15 km away etc as follows
Using this code in ItemDataBound :
private void bindDataList(string location)
{
DataSet dstProperty = Tbl_PropertyMaster.getPropertiesByLocation(location);
dlstNearbyProperties.DataSource = dstProperty;
dlstNearbyProperties.DataBind();
}
.
protected void dlstNearbyProperties_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblPropId = (Label)e.Item.FindControl("lblPropId");
Label lblKmAway = (Label)e.Item.FindControl("lblKmAway");
Label lblPrice = (Label)e.Item.FindControl("lblPrice");
DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(Convert.ToInt32(lblPropId.Text));
if (dstEnabledStat.Tables[0].Rows.Count > 0)
{
//string origin = "8.5572357 ,76.87649310000006";
string origin = InitialOrigin;
string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
lblKmAway.Text = devTools.getDistance(origin, destination) + " Away";
}
lblPrice.Text = getMinnimumOfRoomPrice(Convert.ToInt32(lblPropId.Text));
}
}
Is there a way to sort these value in ascendind or descening w.r.t distances .
NB: Distances are not DB values,they are dynamic.
Can this be sorted in a Button1_Click ?
Alrite after lot of hours of playing with codes I did it.
The following is for GRIDVIEW,Similar steps can be followed for DataList As well.
Page Load : I added an extra column 'Miles' to the already existing datatable
protected void Page_Load(object sender, EventArgs e)
{
dtbl = Tbl_PropertyMaster.SelectAllPropertyAndUserDetails().Tables[0];
dtbl.Columns.Add("Miles", typeof(int));
//userId = devTools.checkAdminLoginStatus();
if (!IsPostBack)
{
fillDlPhotoViewAll();
FillGrProperty();
}
}
Row Data Bound :
protected void grProperty_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(PropId);
if (dstEnabledStat.Tables[0].Rows.Count > 0)
{
string origin = InitialOrigin;
string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
decimal Kilometre=0.00M;
if(devTools.getDistance(origin, destination)!=0)
{
Kilometre=Convert.ToDecimal(devTools.getDistance(origin, destination))/1000;
}
lblmiles.Text = Kilometre.ToString() + "Kms";
dtbl.Rows[inn]["Miles"] = Convert.ToInt32(devTools.getDistance(origin, destination));
inn = inn + 1;
}
}
ViewState["dtbl"] = dtbl;
}
Sort by distance Button_Click:
protected void btnSort_Click(object sender, EventArgs e)
{
DataTable dataTable;
dataTable = (DataTable)ViewState["dtbl"];
if (dataTable.Rows.Count > 0)
{
dataTable.DefaultView.Sort = "Miles DESC";
dataTable.AcceptChanges();
grProperty.DataSource = dataTable;
grProperty.DataBind();
}
}
Related
I've got incredibly weird problem. I'm making memo game app on windows phone. When I click 2 buttons and if they have the same content they should collapse. Problem is that even if they have the same content for example 1 it shows me that this statement is false! Like 1 was not equal 1.
Here's the code:
public partial class Memo : PhoneApplicationPage
{
private int points = 100;
private string[] numbers={"a","a"};
private Button selected_button;
public Memo()
{
InitializeComponent();
button1.Content = numbers[0];
button2.Content = numbers[1];
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if (selected_button != null)
{
PageTitle.Text = "" + selected_button.Content + " " + button1.Content;
if (selected_button.Content == button1.Content)
{
button1.Visibility = Visibility.Collapsed;
selected_button.Visibility = Visibility.Collapsed;
points += 3;
}
else
{
points -= 1;
selected_button.Background = new SolidColorBrush(Colors.White);
}
selected_button = null;
//PageTitle.Text = "" + points;
}
else
{
selected_button = button1;
selected_button.Background = new SolidColorBrush(Colors.Green);
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if (selected_button != null)
{
PageTitle.Text = "" + selected_button.Content + " " + button2.Content;
if (selected_button.Content == button2.Content)
{
button2.Visibility = Visibility.Collapsed;
selected_button.Visibility = Visibility.Collapsed;
points += 3;
}
else
{
points -= 1;
selected_button.Background = new SolidColorBrush(Colors.White);
}
selected_button = null;
//PageTitle.Text = "" + points;
}
else
{
selected_button = button2;
selected_button.Background = new SolidColorBrush(Colors.Green);
}
}
private void button11_Click(object sender, RoutedEventArgs e)
{
button11.Visibility = Visibility.Collapsed;
}
}
Please help :)
I used following code to drag and drop Button in C# and it works like charm when my Form.RightToLeftLayout=False,
but
when I set RightToLeftLayout=True
it doesnt work and move the control in wrong direction!!!
public partial class Form1 : Form
{
int xPosition;
int yPosition;
bool isDraged;
public Form1()
{
InitializeComponent();
}
private void btnMoveable_MouseDown(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.SizeAll;
xPosition = e.X;
yPosition = e.Y;
isDraged = true;
}
private void btnMoveable_MouseUp(object sender, MouseEventArgs e)
{
isDraged = false;
this.Cursor = Cursors.Default;
}
private void btnMoveable_MouseMove(object sender, MouseEventArgs e)
{
if (isDraged)
{
btnMoveable.Left = btnMoveable.Left + e.X - xPosition;
btnMoveable.Top = btnMoveable.Top + e.Y - yPosition;
}
}
}
Well, you're discovering how RightToLeft is implemented. Everything is still in their normal logical position but the coordinate system is mirror-imaged along the Y-axis. So movement along the X-axis is inverted. You'll need to accommodate that. Fix:
int dx = e.X - xPosition;
if (this.RightToLeft == RightToLeft.Yes) dx = -dx;
btnMoveable.Left = btnMoveable.Left + dx;
I am developing a Windows 8 app using WinJS. I am trying to get the touch coordinates for pinch and zoom. I have implemented the gesture manipulation handlers via Windows.UI.Input.GestureRecognizer. I am triggering my pinch and zoom logic when for the "manipulationupdated" event, event.delta.scale is not 1. When manipulation happens inside the "manipulationupdated" event object I find coordinates of only 1 position. How do I calculate both the finger touch coordinates from this information?
Also how do I know which touch coordinate the position belong to? I find the position repeated multiple times inside the event object - at event.position and event.detail[0].position
What I am trying to achieve is performing pinch and zoom in a chart(much like a map). Kindly help me out with these questions.
public class PZBehavior : Behavior
{
bool _isDragging;
bool _isPinching;
Point _ptPinchPositionStart;
private Image _imgZoom;
private ScaleTransform _scaleTransform;
private RotateTransform _rotateTransform;
private TranslateTransform _translateTransform;
private MatrixTransform _previousTransform;
private TransformGroup _parentGroup;
private TransformGroup _currentTransform;
protected override void OnAttached()
{
_imgZoom = AssociatedObject;
_imgZoom.RenderTransform = BuildTrasnformGroup();
var listener = GestureService.GetGestureListener(AssociatedObject);
listener.DragStarted += DragStarted;
listener.DragDelta += DragDelta;
listener.DragCompleted += DragCompleted;
listener.PinchStarted += PinchStarted;
listener.PinchDelta += PinchDelta;
listener.PinchCompleted += PinchCompleted;
}
private TransformGroup BuildTrasnformGroup()
{
_parentGroup = new TransformGroup();
_currentTransform = new TransformGroup();
_previousTransform = new MatrixTransform();
_scaleTransform = new ScaleTransform();
_rotateTransform = new RotateTransform();
_translateTransform = new TranslateTransform();
_currentTransform.Children.Add(_scaleTransform);
_currentTransform.Children.Add(_rotateTransform);
_currentTransform.Children.Add(_translateTransform);
_parentGroup.Children.Add(_previousTransform);
_parentGroup.Children.Add(_currentTransform);
return _parentGroup;
}
void PinchCompleted(object sender, PinchGestureEventArgs e)
{
if (_isPinching)
{
TransferTransforms();
_isPinching = false;
}
}
void PinchDelta(object sender, PinchGestureEventArgs e)
{
if (_isPinching)
{
// Set scaling
_scaleTransform.ScaleX = e.DistanceRatio;
_scaleTransform.ScaleY = e.DistanceRatio;
// Optionally set rotation
_rotateTransform.Angle = e.TotalAngleDelta;
// Set translation
Point ptPinchPosition = new Point(0,0);
_translateTransform.X = ptPinchPosition.X - _ptPinchPositionStart.X;
_translateTransform.Y = ptPinchPosition.Y - _ptPinchPositionStart.Y;
}
}
void PinchStarted(object sender, PinchStartedGestureEventArgs e)
{
_isPinching = e.OriginalSource == _imgZoom;
if (_isPinching)
{
// Set transform centers
Point ptPinchCenter = e.GetPosition(_imgZoom);
ptPinchCenter = _previousTransform.Transform(ptPinchCenter);
_scaleTransform.CenterX = ptPinchCenter.X;
_scaleTransform.CenterY = ptPinchCenter.Y;
_rotateTransform.CenterX = ptPinchCenter.X;
_rotateTransform.CenterY = ptPinchCenter.Y;
_ptPinchPositionStart = new Point(0,0);
}
}
void DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
if (_isDragging)
{
TransferTransforms();
_isDragging = false;
}
}
void DragDelta(object sender, DragDeltaGestureEventArgs e)
{
if (_isDragging)
{
_translateTransform.X += e.HorizontalChange;
_translateTransform.Y += e.VerticalChange;
}
}
void DragStarted(object sender, DragStartedGestureEventArgs e)
{
_isDragging = e.OriginalSource == _imgZoom;
}
void TransferTransforms()
{
_previousTransform.Matrix = Multiply(_previousTransform.Matrix, _currentTransform.Value);
// Set current transforms to default values
_scaleTransform.ScaleX = _scaleTransform.ScaleY = 1;
_scaleTransform.CenterX = _scaleTransform.CenterY = 0;
_rotateTransform.Angle = 0;
_rotateTransform.CenterX = _rotateTransform.CenterY = 0;
_translateTransform.X = _translateTransform.Y = 0;
}
Matrix Multiply(Matrix a, Matrix b)
{
return new Matrix(a.M11 * b.M11 + a.M12 * b.M21,
a.M11 * b.M12 + a.M12 * b.M22,
a.M21 * b.M11 + a.M22 * b.M21,
a.M21 * b.M12 + a.M22 * b.M22,
a.OffsetX * b.M11 + a.OffsetY * b.M21 + b.OffsetX,
a.OffsetX * b.M12 + a.OffsetY * b.M22 + b.OffsetY);
}
}
Please help me, how I can find the highest number in each column and format it to make it Bold.
Please use this approch.
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
string[] numericColumns = { "OrderID", "Freight", "Freight1", "Freight2" };
foreach (string uniqueName in numericColumns)
{
int index = -1;
decimal maxNumber = decimal.MinValue;
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
decimal currentNumber = decimal.Parse(dataItem[uniqueName].Text);
if (currentNumber > maxNumber)
{
maxNumber = currentNumber;
index = dataItem.ItemIndex;
}
}
if (index >= 0)
{
GridTableCell cell = (RadGrid1.Items[index] as GridDataItem)[uniqueName] as GridTableCell;
cell.BackColor = System.Drawing.Color.LightBlue;
}
}
}
Hope this will work for you.
I am trying to re size the data grid view in windows form. There are two data grid view on my form and both are fed from the database. Is there any was I can resize the data grid view on the left so that it grows with the content length and width and the data grid view shrinks with the content.
Given below is my code
private void show_Click(object sender, EventArgs e)
{
int rowIndex = Convert.ToInt32(productGridView.SelectedRows[0].Cells[2].Value);
//IEnumerable<Supplier> supplierQuery = from supplier in newNorthWindContext.Suppliers
// where supplier.SupplierID == rowIndex
// select new {} supplier;
IEnumerable<Supplier> supplierQuery = newNorthWindContext.Suppliers.Where(supliers => supliers.SupplierID == rowIndex);
supplierDataGridView.DataSource = ((ObjectQuery)supplierQuery).Execute(MergeOption.AppendOnly);
supplierDataGridView.Columns["SupplierID"].Visible = false;
supplierDataGridView.Columns["ContactTitle"].Visible = false;
supplierDataGridView.Columns["Address"].Visible = false;
supplierDataGridView.Columns["City"].Visible = false;
supplierDataGridView.Columns["Region"].Visible = false;
supplierDataGridView.Columns["PostalCode"].Visible = false;
supplierDataGridView.Columns["ContactTitle"].Visible = false;
supplierDataGridView.Columns["Address"].Visible = false;
//supplierDataGridView.AutoResizeColumns();
supplierDataGridView.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
}
private void categoryDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
Category category = (Category)this.categoryDropDown.SelectedItem;
try
{
productGridView.DataSource = category.Products;
productGridView.Columns["SupplierID"].Visible = false;
productGridView.Columns["CategoryID"].Visible = false;
productGridView.Columns["Category"].Visible = false;
productGridView.Columns["Order_Details"].Visible = false;
productGridView.Columns["Supplier"].Visible = false;
productGridView.AllowUserToDeleteRows = true;
productGridView.AutoResizeColumns();
productGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ProductDetail_Load(object sender, EventArgs e)
{
newNorthWindContext = new NorthwindEntities();
productGridView.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
IEnumerable<Category> categoryQuery = from category in newNorthWindContext.Categories.Include("Products")
orderby category.CategoryName
select category;
try
{
this.categoryDropDown.DataSource = ((ObjectQuery)categoryQuery).Execute(MergeOption.AppendOnly);
this.categoryDropDown.DisplayMember = "categoryName";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
This solves the issue.
supplierDataGridView.Width = supplierDataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+4;
at the end of show_Click you should have something like
supplierDataGridView.Width = supplierDataGridView.Columns.Sum(x => x.Width) + supplierDataGridView.RowHeadersWidth + 2;
supplierDataGridView.Height = supplierDataGridView.GetRowDisplayRectangle(supplierDataGridView.NewRowIndex, true).Bottom + supplierDataGridView.GetRowDisplayRectangle(supplierDataGridView.NewRowIndex, false).Height;
I hope this helps!