Skipping Tab Index on Non Editable column - vb.net

How to allow Setting Tabindex within the c1 FlexGrid in such a way that it skips a particular column in the c1 FlexGrid.
Is there something I can too do this
Thanks!

There might be a better way, but here's one approach:
public partial class Form1 : Form
{
private Int32 _colIdxToSkip = 4; //Remember, there's an extra column if "Row Headers" are turned on!
private Keys _lastKeys = Keys.None;
public Form1()
{
InitializeComponent();
flexGrid.KeyActionTab = C1.Win.C1FlexGrid.KeyActionEnum.MoveAcross;
}
private void flexGrid_BeforeRowColChange(Object sender, C1.Win.C1FlexGrid.RangeEventArgs e)
{
if (_lastKeys == Keys.Tab && e.OldRange.r1 == e.NewRange.r1 && e.NewRange.c1 == _colIdxToSkip)
{
if (_colIdxToSkip == flexGrid.Cols.Count - 1)
{
flexGrid.Row = (flexGrid.Row == flexGrid.Rows.Count - 1 ? flexGrid.Rows.Fixed : flexGrid.Row + 1);
flexGrid.Col = flexGrid.Cols.Fixed;
}
else
flexGrid.Col = _colIdxToSkip + 1;
e.Cancel = true;
}
}
private void flexGrid_KeyDown(Object sender, KeyEventArgs e)
{
_lastKeys = e.KeyCode;
}
}

Related

Custom Renderer for Dashed Border of frame in UWP Xamarin

I want a frame with a dashed border (as shown in the image). I am looking for UWP Renderer if anyone has any suggestions on that please share them with me. I am stuck with this.
Custom Renderer for Dashed Border of frame in UWP Xamarin
Current there is not such Dashed Border of frame in UWP Xamarin, but you can make it with Rectangle and set available StrokeDashArray to implement it and then use ViewRenderer to render it within Xamarin. We will share DashedBorderRenderer below, for the complete control please refer code sample here.
public class DashedBorderRenderer : ViewRenderer<DashedBorder, DottedBorder>
{
DottedBorder _dottedBorder;
FrameworkElement _navtiveContent;
double defaultPadding = 2;
bool isOpened;
public DashedBorderRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<DashedBorder> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
_navtiveContent.Loaded -= Native_Loaded;
_navtiveContent.SizeChanged -= Native_SizeChanged;
}
if (e.NewElement != null)
{
if (Control != null)
{
var stroke = Element.DashedStroke == 0 ? Element.DashedStroke : 2.0;
var borderColor = Element.BorderColor.ToWindowsColor() == null ? Element.BorderColor.ToWindowsColor() : Colors.Red;
Control.DashedStroke = new Windows.UI.Xaml.Media.DoubleCollection() { stroke };
Control.StrokeBrush = new Windows.UI.Xaml.Media.SolidColorBrush(borderColor);
}
else
{
_dottedBorder = new DottedBorder();
_navtiveContent = Element.Content.GetOrCreateRenderer().GetNativeElement() as FrameworkElement;
_navtiveContent.Loaded += Native_Loaded;
_navtiveContent.SizeChanged += Native_SizeChanged;
var stroke = Element.DashedStroke == 0 ? 2.0 : Element.DashedStroke;
var borderColor = Element.BorderColor.ToWindowsColor() == null ? Element.BorderColor.ToWindowsColor() : Colors.Red;
_dottedBorder.DashedStroke = new Windows.UI.Xaml.Media.DoubleCollection() { stroke };
_dottedBorder.StrokeBrush = new Windows.UI.Xaml.Media.SolidColorBrush(borderColor);
SetNativeControl(_dottedBorder);
}
}
}
private void Native_SizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateSize(sender);
}
private void Native_Loaded(object sender, RoutedEventArgs e)
{
UpdateSize(sender);
}
private void UpdateSize(object sender)
{
var content = sender as FrameworkElement;
if (content is Windows.UI.Xaml.Controls.Image)
{
if (!isOpened)
{
(content as Windows.UI.Xaml.Controls.Image).ImageOpened += (s, e) =>
{
isOpened = true;
var image = sender as Windows.UI.Xaml.Controls.Image;
_dottedBorder.Height = image.ActualHeight + defaultPadding;
_dottedBorder.Width = image.ActualWidth + defaultPadding;
};
}
else
{
_dottedBorder.Height = content.ActualHeight + defaultPadding;
_dottedBorder.Width = content.ActualWidth + defaultPadding;
}
}
_dottedBorder.Height = content.ActualHeight+defaultPadding;
_dottedBorder.Width = content.ActualWidth + defaultPadding;
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
}
}

ScrollIntoView to SelectedItem with MVVM (Windows Phone 8.1)

In code behind this is done by
ActivityList.ScrollIntoView(ActivityList.SelectedItem);
when you come back from the detailpage so that when you return from the detailpage you don't have to start from the top of the ListView.
There are a few examples to scroll to the end of a ListView but not to the SelectedItem.
But how is this done in MVVM? Creating a Behavior with Behavior SDK? And how?
I've done this with an attached-property (behavior). This behavior is in a class called DataGridExtensions and looks like:
public static readonly DependencyProperty ScrollSelectionIntoViewProperty = DependencyProperty.RegisterAttached(
"ScrollSelectionIntoView", typeof(bool), typeof(DataGridExtensions), new PropertyMetadata(false, ScrollSelectionIntoViewChanged));
private static void ScrollSelectionIntoViewChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
DataGrid dataGrid = d as DataGrid;
if (dataGrid == null)
return;
if (e.NewValue is bool && (bool)e.NewValue)
dataGrid.SelectionChanged += DataGridOnSelectionChanged;
else
dataGrid.SelectionChanged -= DataGridOnSelectionChanged;
}
private static void DataGridOnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems == null || e.AddedItems.Count == 0)
return;
DataGrid dataGrid = sender as DataGrid;
if (dataGrid == null)
return;
ScrollViewer scrollViewer = UIHelper.FindChildren<ScrollViewer>(dataGrid).FirstOrDefault();
if (scrollViewer != null)
{
dataGrid.ScrollIntoView(e.AddedItems[0]);
}
}
public static void SetScrollSelectionIntoView(DependencyObject element, bool value)
{
element.SetValue(ScrollSelectionIntoViewProperty, value);
}
public static bool GetScrollSelectionIntoView(DependencyObject element)
{
return (bool)element.GetValue(ScrollSelectionIntoViewProperty);
}
The code of UIHelper.FindChildren is:
public static IList<T> FindChildren<T>(DependencyObject element) where T : FrameworkElement
{
List<T> retval = new List<T>();
for (int counter = 0; counter < VisualTreeHelper.GetChildrenCount(element); counter++)
{
FrameworkElement toadd = VisualTreeHelper.GetChild(element, counter) as FrameworkElement;
if (toadd != null)
{
T correctlyTyped = toadd as T;
if (correctlyTyped != null)
{
retval.Add(correctlyTyped);
}
else
{
retval.AddRange(FindChildren<T>(toadd));
}
}
}
return retval;
}

How to search the record in the sql adapter or datatable,

How to search the records in data-table,in my application I am having plenty of records.
For eg: After the searching completes I am getting 50 records out of 1000, from the table, now I want to do the first, next, previous and last record navigation for this searched records only. how can I do this, I have done for normal navigation(directly connecting to sql) but getting some difficulty in showing navigation in searched records.
try this
var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;
Here i assume that you have fetched data into Datatable using "fetchData()" method.
// Global variable
DataTable dt_rec = new DataTable();
int rowCount = 1;
int lastRowNum = 0;
In the form_load event, you called the "fetchData()" method. After then you click on "Next" button click event which look like this.
private void NextButton_Click(System.Object sender, System.EventArgs e)
{
if (lastRowNum > rowCount) {
rowCount = rowCount + 1;
setControlValue(dt_rec.Rows(rowCount - 1));
} else {
Interaction.MsgBox("Record Not Found", "Test");
}
}
And here is the "Previous" button click event.
private void Previous_Click(System.Object sender, System.EventArgs e)
{
if (rowCount > 1) {
rowCount = rowCount - 1;
setControlValue(dt_rec.Rows(rowCount - 1));
} else {
Interaction.MsgBox("Record Not Found", "Test");
}
}
And here is the click event of "First" button.
private void FirstButton_Click(System.Object sender, System.EventArgs e)
{
if (rowCount != 1) {
rowCount = 1;
setControlValue(dt_rec.Rows(0));
} else {
Interaction.MsgBox("Record Not Found", "Test");
}
}
And finally the "Last" click event.
private void LastButton_Click(System.Object sender, System.EventArgs e)
{
if (rowCount < lastRowNum) {
rowCount = lastRowNum;
setControlValue(dt_rec.Rows(lastRowNum - 1));
} else {
Interaction.MsgBox("Record Not Found", "Test");
}
}
Here you find the setControlValue() method which will set the control value. For exa.
public void setControlValue(DataRow dr)
{
if (!string.IsNullOrEmpty(dr["UserId"])) {
txtUserName.Text = dr["UserId"].ToString();
}
if (!string.IsNullOrEmpty(dr["WebUrl"])) {
txtWebUrl.Text = dr["WebUrl"].ToString();
}
// and so on.....
}
Hope all these thing might help you...

Janus 4 GridEx disable rows

I have have a Janus 4 GridEx control which includes a checkbox column.
I need to be able to disable certain rows (i.e make them non selectable/greyed out) depending the value of a particular column. The data for the grid is loaded from a database.
Any help would be appreciated.
You have to utilize the LoadingRow and SelectionChanged events of the Janus Grid.
This is a sample code: ( Here I'm checking the value of a particular column to be divided by 2)
private void grdEx_LoadingRow(object sender, Janus.Windows.GridEX.RowLoadEventArgs e)
{
if (Convert.ToInt32(e.Row.Cells["ID"].Value) % 2 == 0)
{
e.Row.RowStyle = new GridEXFormatStyle(e.Row.Table.RowFormatStyle);
e.Row.RowStyle.BackColor = Color.Gray;
}
}
private void grdEx_SelectionChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(grdEx.GetValue("ID")) % 2 == 0)
{
if (grdEx.Row >= 0)
{
if (grdEx.Row == grdEx.RowCount - 1)
grdEx.Row = grdEx.Row - 1;
else
grdEx.Row = grdEx.Row + 1;
}
}
}
Depending on the Checkbox column , just see the sample code:
private void grdEX1_FormattingRow(object sender, RowLoadEventArgs e)
{
if (e.Row.RowIndex > -1 && e.Row.RowIndex < grdEX1.RowCount)
{
for (int i = 0; i < grdEX1.RootTable.Columns.Count; i++)
{
if (!Convert.ToBoolean(e.Row.Cells["checkboxCol"].Value))//checked So editable
{
e.Row.Cells[i].FormatStyle = new GridEXFormatStyle() { BackColor = Color.LightGray };
}
else
{
e.Row.Cells[i].FormatStyle = null;
}
}
}
}
To prevent the editing if the row is not checked :
private void grdEX1_EditingCell(object sender, EditingCellEventArgs e)
{
if(!Convert.ToBoolean(grdEX1.GetValue("checkboxCol"))) //not checked
{
e.Cancel = true;
return;
}
}

Error in DataGrid random behavior when scrolling in Silverlight 4.0

I have a datagrid and its rows are colored based on certain condtions..There is a vertical scrollbar for my datagrid.. If the user scrolls the datagrid the index of the colored rows r getting changed.. For eg: if 2 row is colored if the user scrolls down and comes up the index of the colored row is getting messed up...
here is the code....
dggeneralconfiguration.LoadingRow += new EventHandler<DataGridRowEventArgs>(grid1_LoadingRow);
dggeneralconfiguration.UnloadingRow += new EventHandler<DataGridRowEventArgs>(grid1_UnloadingRow);
void grid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid;
if (c.Status == false)
{
if (e.Row != null)
{
e.Row.Background = new SolidColorBrush(Colors.Red);
//e.Row.Background = new SolidColorBrush(Colors.Transparent);
}
}
}
void grid1_UnloadingRow(object sender, DataGridRowEventArgs e)
{
ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid;
if (c.Status == false)
{
if (e.Row != null)
{
e.Row.Background = new SolidColorBrush(Colors.Red);
//e.Row.Background = new SolidColorBrush(Colors.Transparent);
}
}
}
Better late than never. ;-) . I too had similar kind of problem.. try assigning row background to null on unloading row event.
private void dg_UnloadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Background = null;
}