Janus 4 GridEx disable rows - vb.net

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;
}
}

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);
}
}

Skipping Tab Index on Non Editable column

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;
}
}

MPAndroidChart multiple real time line chart - entries not added at correct xIndex

I modified a little bit the Real Time Line Chart example to show two LineChart like the code below.
Problem: the ViewPort is moving incorrectly does not work properly. It is moving much faster than real points (Entry) are added. In other words, the Entry get added in the wrong place and the ViewPort keeps moving right uncontrollably. It should move right only gradually as each Entry is added. Please help me to fix this one.
private int year = 2015;
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss.SSS");
private int[] mColors = {Color.BLUE,Color.YELLOW,Color.CYAN,Color.MAGENTA,Color.GREEN};
private int mCurrentColorIndex = 0;
private synchronized void addEntry(String id, float value) {
LineData data = mChart.getData();
if (data != null) {
ILineDataSet set = data.getDataSetByLabel(id,true);
//ILineDataSet set1 = data.getDataSetByIndex(0);
if (set == null) {
set = createSet(id, mColors[(mCurrentColorIndex++)%mColors.length ]);
data.addDataSet(set);
}
String xValue = sdf.format(new Date());
// add a new x-value first
data.addXValue(xValue);
set.addEntry(new Entry(value, set.getEntryCount(), 0));
// let the chart know it's data has changed
mChart.notifyDataSetChanged();
// limit the number of visible entries
mChart.setVisibleXRangeMaximum(30);
// mChart.setVisibleYRange(30, AxisDependency.LEFT);
// move to the latest entry
mChart.moveViewToX(data.getXValCount() - 31);
// this automatically refreshes the chart (calls invalidate())
// mChart.moveViewTo(data.getXValCount()-7, 55f,
// AxisDependency.LEFT);
}
}
private LineDataSet createSet(String label, int color) {
LineDataSet set = new LineDataSet(null, label);
set.setAxisDependency(AxisDependency.LEFT);
set.setColor(color);
set.setCircleColor(Color.WHITE);
set.setLineWidth(2f);
set.setCircleRadius(4f);
set.setFillAlpha(65);
set.setFillColor(color);
set.setHighLightColor(Color.rgb(244, 117, 117));
set.setValueTextColor(Color.WHITE);
set.setValueTextSize(9f);
set.setDrawValues(false);
return set;
}
private void feedMultiple() {
new Thread(new Runnable() {
#Override
public void run() {
for(int i = 0; i < 50; i++) {
runOnUiThread(new Runnable() {
#Override
public void run() {
addEntry("name1", (float)(Math.random() * 40) + 30f);
}
});
try {
Thread.sleep(35);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
new Thread(new Runnable() {
#Override
public void run() {
for(int i = 0; i < 100; i++) {
runOnUiThread(new Runnable() {
#Override
public void run() {
addEntry("name2", (float)(Math.random() * 40) + 30f);
}
});
try {
Thread.sleep(35);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
Resolved in the comments by #Tony with the following change:
//set.addEntry(new Entry(value, set.getEntryCount(), 0)); //incorrect
set.addEntry(new Entry(value, data.getXValCount(), 0)); //correct
Explanation:
A LineData is composed of multiple ILineDataSet:
set.getEntryCount() returns the number of y-values in one DataSet and is effectively equivalent to yvals.size().
data.getXValCount() returns the total number of x-values the ChartData object represents.
Since we wish to add an entry at the last x-index, we should use data.getXValCount()
NOTE:
In MPAndroidCharts 3.0.1 data.getXValCount() is no longer present. You can instead use data.getXMax() + 1 instead.

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...

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;
}