Add Dynamic Check Box in Grid Takes Time in Silverlight - silverlight

I Have a Grid (BrkGrid) in ViewMode... I Add dynamic Check Box (brkChkBox) depending on some logic. A foreach is responsible for adding check boxes to a specific row and column of this grid.. But it takes time while adding check boxes to the BrkGrid.. When I Comment the Add Statement (BrkGrid.Children.Add(brkChkBox)) then the code executes faster.. Any help will be highly appreciated...
CheckBox brkChkBox = null;
foreach (var s in this.ViewData.PlnDtShiftBrksDateList)
{
brkChkBox = new CheckBox
{
DataContext = s,
Tag = s.BreakID,
Width = 20,
VerticalAlignment = VerticalAlignment.Top,
};
Binding chkBoxBinding = new Binding("IsSelected");
chkBoxBinding.Source = s;
chkBoxBinding.Mode = BindingMode.TwoWay;
brkChkBox.SetBinding(CheckBox.IsCheckedProperty, chkBoxBinding);
brkChkBox.Click += brkChkBox_Click;
Grid.SetColumn(brkChkBox, gridColDic.FirstOrDefault(x => x.Key == s.BreakID).Value);
Grid.SetRow(brkChkBox, gridRowDic.FirstOrDefault(x => x.Key.Date == s.Date.Date).Value);
BrkGrid.Children.Add(brkChkBox);
}

Related

Immediately update DataGridViewCheckBoxCell

I am programmatically updating my WinForm DataGridView
Problem, DataGridViewCheckBoxCell doesn't get updated !!!
I was google, it seams like knowing case but whatever I've tried did not help yet.
private void InitializeFunctionsDataGrid()
{
System.Data.DataSet ds = func.GetFunctions();
this.FunctionsDataGrid.DataSource = ds.Tables[0];
this.FunctionsDataGrid.Columns["FunctionId"].Visible = false;
this.FunctionsDataGrid.Columns["DESCRIPTION"].Width = 370;
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
column.Name = "enable";
column.HeaderText = "enable";
column.FalseValue = 0;
column.TrueValue = 1;
FunctionsDataGrid.Columns.Add(column);
foreach(DataGridViewRow row in FunctionsDataGrid.Rows)
{
(( DataGridViewCheckBoxCell)row.Cells["enable"]).Value = 1;
}
FunctionsDataGrid.CurrentCell = null;
}
enable is an unbound column. This means that you need to provide cell value yourself.
You can set the VirtualMode property to true and handle the CellValueNeeded event.
If you want to enable the user to check a cell then you need to handle the CellValuePushed event.
DataGridView samples that are part of the DataGridView FAQ has a specific example of an unbound checkbox column along with databound columns.
OK basically easiest way for me was to work with datasource.
I've add the column to the DataTable and fill it with data.
And then last thing this.FunctionsDataGrid.DataSource = ds.Tables[0];

GTK CellRendererCombo set value into appropriate cell

What I'm trying to do it a TreeView that have several columns. The first column is a ComboBox, which means that I use Gtk.CellRendererCombo. The thing is, when I selected a value from the ComboBox, I'd like the Text from the cell to change from "" to the value I just selected. It feasible if at the Gtk.CellRendererCombo.Edited event I set the columns Text field to the EditedArgs.NewText.
The problem is, each time I set a value, I create a new row, and I'd like the Text Field to act like it does in the Gtk.CellRendererText, but it doesn't. It's not a different value for each row at that column, but the same value as setted in the Gtk.CellRendererCombo.Text
The Gtk.CellRenderer should not contain any state, so OK, using the Text field is a really bad idea from what I'm trying to do.
But if I set some value from the Gtk.ListStore that is the Model of my TreeView (Which is different from the Model for the Gtk.CellRendererCombo). The values setted will never show at the Column of the ComboBox.
class Program
{
private static Gtk.TreeView treeview = null;
static void OnEdited(object sender, Gtk.EditedArgs args)
{
Gtk.TreeSelection selection = treeview.Selection;
Gtk.TreeIter iter;
selection.GetSelected(out iter);
treeview.Model.SetValue(iter, 0, args.NewText); // the CellRendererCombo
treeview.Model.SetValue(iter, 1, args.NewText); // the CellRendererText
//(sender as Gtk.CellRendererCombo).Text = args.NewText; // Will set all the Cells of this Column to the Selection's Text
}
static void Main(string[] args)
{
Gtk.Application.Init();
Gtk.Window window = new Window("TreeView ComboTest");
window.WidthRequest = 200;
window.HeightRequest = 150;
Gtk.ListStore treeModel = new ListStore(typeof(string), typeof(string));
treeview = new TreeView(treeModel);
// Values to be chosen in the ComboBox
Gtk.ListStore comboModel = new ListStore(typeof(string));
Gtk.ComboBox comboBox = new ComboBox(comboModel);
comboBox.AppendText("<Please select>");
comboBox.AppendText("A");
comboBox.AppendText("B");
comboBox.AppendText("C");
comboBox.Active = 0;
Gtk.TreeViewColumn comboCol = new TreeViewColumn();
Gtk.CellRendererCombo comboCell = new CellRendererCombo();
comboCol.Title = "Combo Column";
comboCol.PackStart(comboCell, true);
comboCell.Editable = true;
comboCell.Edited += OnEdited;
comboCell.TextColumn = 0;
comboCell.Text = comboBox.ActiveText;
comboCell.Model = comboModel;
comboCell.WidthChars = 20;
Gtk.TreeViewColumn valueCol = new TreeViewColumn();
Gtk.CellRendererText valueCell = new CellRendererText();
valueCol.Title = "Value";
valueCol.PackStart(valueCell, true);
valueCol.AddAttribute(valueCell, "text", 1);
treeview.AppendColumn(comboCol);
treeview.AppendColumn(valueCol);
// Append the values used for the tests
treeModel.AppendValues("comboBox1", string.Empty); // the string value setted for the first column does not appear.
treeModel.AppendValues("comboBox2", string.Empty);
treeModel.AppendValues("comboBox3", string.Empty);
window.Add(treeview);
window.ShowAll();
Gtk.Application.Run();
}
}
I'd like the Cell of the ComboBox in which the selection has been made to show the value, but continue to be editable for later changes.
If someone has a way of doing this, I would be very grateful for you input. thanks.
Update:
What I think, because Gtk.CellRendererCombo inherits from Gtk.CellRendererText it just ignores the value setted in the cell. Now, I guess I could create a custom MyCellRendererCombo that inherits from Gtk.CellRendererCombo and use the value setted in the cell when supplied for the rendering, but the documentation on the difference between Gtk.CellRendererText and Gtk.CellRendererCombo is quite slim... I guess I should visit the implementation in C to know the details.
Ok, I've found a solution to my problem, I use a "hidden" column in which I read the "text" value. The hidden column contains the Gtk.CellRendererText, the Gtk.CellRendererCombo must have an Attribute Mapping with the new Column.
The resulting code is below:
class Program
{
private static Gtk.TreeView treeview = null;
static void OnEdited(object sender, Gtk.EditedArgs args)
{
Gtk.TreeSelection selection = treeview.Selection;
Gtk.TreeIter iter;
selection.GetSelected(out iter);
treeview.Model.SetValue(iter, 1, args.NewText); // the CellRendererText
}
static void Main(string[] args)
{
Gtk.Application.Init();
Gtk.Window window = new Window("TreeView ComboTest");
window.WidthRequest = 200;
window.HeightRequest = 150;
Gtk.ListStore treeModel = new ListStore(typeof(string), typeof(string));
treeview = new TreeView(treeModel);
// Values to be chosen in the ComboBox
Gtk.ListStore comboModel = new ListStore(typeof(string));
Gtk.ComboBox comboBox = new ComboBox(comboModel);
comboBox.AppendText("<Please select>");
comboBox.AppendText("A");
comboBox.AppendText("B");
comboBox.AppendText("C");
comboBox.Active = 0;
Gtk.TreeViewColumn comboCol = new TreeViewColumn();
Gtk.CellRendererCombo comboCell = new CellRendererCombo();
comboCol.Title = "Combo Column";
comboCol.PackStart(comboCell, true);
comboCol.AddAttribute(comboCell, "text", 1);
comboCell.Editable = true;
comboCell.Edited += OnEdited;
comboCell.TextColumn = 0;
comboCell.Text = comboBox.ActiveText;
comboCell.Model = comboModel;
comboCell.WidthChars = 20;
Gtk.TreeViewColumn valueCol = new TreeViewColumn();
Gtk.CellRendererText valueCell = new CellRendererText();
valueCol.Title = "Value";
valueCol.PackStart(valueCell, true);
valueCol.AddAttribute(valueCell, "text", 1);
valueCol.Visible = false;
treeview.AppendColumn(comboCol);
treeview.AppendColumn(valueCol);
// Append the values used for the tests
treeModel.AppendValues("comboBox1", "<Please select>"); // the string value setted for the first column does not appear.
treeModel.AppendValues("comboBox2", "<Please select>");
treeModel.AppendValues("comboBox3", "<Please select>");
window.Add(treeview);
window.ShowAll();
Gtk.Application.Run();
}
}

telerik listcontrol only shows part of item image

I am filling a listcontrol (Telerik for WinForms) by using the following code :
public static List<RadListDataItem> GetItems()
{
List<RadListDataItem> items = new List<RadListDataItem>();
for (int i = 1; i <= 10; i++)
{
RadListDataItem toadd = new RadListDataItem();
toadd.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
toadd.Text = "sssssssssss";
//toadd.Image.
string imagename = "MyProject.SuIcons.d" + i + ".JPG";
toadd.Image = new Bitmap(Assembly.GetExecutingAssembly().
GetManifestResourceStream(imagename));
items.Add(toadd);
}
return items;
}
but, only top portition of every item image is show in listcontrol, I mean I cant see the whole image associated with item in the list.
Would you help me please ?
You should set the AutoSizeItems property of the control to true in order to allow the visual items size themselves according to their content:
radListControl1.AutoSizeItems = true;
You can adjust the item size of the radListView. There is a property ItemSize that you can change in the designer view. Or if you want to do it programmatically, you can do something like this.
radListView1.ItemSize = new System.Drawing.Size(200, 400);
The first parameter is the width and the second is the height.

Add button column in a databound datagridview

i have a datagridview. i bound it to a list. now i want to show a column at the end of it. but that column apprear in wrong possition.
this is my code
grdPatientAppointment.DataSource = lst;
grdPatientAppointment.Columns["ID"].Visible = false;
//grdPatientAppointment.Columns["AdmitDate"].Visible = false;
//grdPatientAppointment.Columns["DischargeDate"].Visible = false;
grdPatientAppointment.Columns["AppointmentID"].Visible = false;
grdPatientAppointment.Columns["PatientrName"].DisplayIndex = 0;
grdPatientAppointment.Columns["Age"].DisplayIndex = 1;
grdPatientAppointment.Columns["Address"].DisplayIndex = 2;
grdPatientAppointment.Columns["ContactNo"].DisplayIndex = 3;
grdPatientAppointment.Columns["Dieseas"].DisplayIndex = 4;
grdPatientAppointment.Columns["AppointmentDate"].DisplayIndex = 5;
DataGridViewButtonColumn btnColumn = new DataGridViewButtonColumn();
btnColumn.HeaderText = "Treat";
btnColumn.Text = "Treat";
btnColumn.UseColumnTextForButtonValue = true;
grdPatientAppointment.Columns.Insert(6,btnColumn);
here is output:
but i want that button to the end of datagrid view
Add column instead of inserting it to the GridView. It will automaticallyy append it to the end of column collection.
grdPatientAppointment.Columns.Add(btnColumn);
Use DisplayIndex property to change the order of the columns:
http://msdn.microsoft.com/en-us/library/wkfe535h.aspx
just add code below
grdPatientAppointment.Columns.Insert(I, btnColumn)
I is index of column you want to add
Use grdPatientAppointment.AutoGenerateColumns = false;
Then add all columns your grid will receive from DataSource and bind them from editor.

Databinding of DataGridViewComboBoxColumn

In the code below, the combo box named "ConnectionType" shows the selected item, but one cannot change the selected item (it seems like there is only one item in the combo box). If I comment out the line
typeCol.DataPropertyName = "ConnectionTypeName";
then the combo box is selectable, but the correct item is not selected, of course. What am I doing wrong??
Thanks.
private void LoadConnectionsGrid()
{
_dc = new EnterpriseEntities();
dataGridViewConnections.AutoGenerateColumns = false;
dataGridViewConnections.DataSource = _dc.Connection.Include("ConnectionType");
DataGridViewComboBoxColumn typeCol =
(DataGridViewComboBoxColumn)dataGridViewConnections.Columns["ConnectionType"];
typeCol.DataPropertyName = "ConnectionTypeName";
var qry = from c in _dc.ConnectionType
select c.Type;
typeCol.DataSource = qry;
DataGridViewTextBoxColumn nameCol =
(DataGridViewTextBoxColumn)dataGridViewConnections.Columns["ConnectionName"];
nameCol.DataPropertyName = "Name";
DataGridViewTextBoxColumn connStrCol =
(DataGridViewTextBoxColumn)dataGridViewConnections.Columns["ConnectionString"];
connStrCol.DataPropertyName = "ConnectionString";
}
Ultimately, I could not get data binding, the entity framework, and comboboxes to play nice and I just created the data grid brute force (code below). This means that I handle inserts, updates and deletes by hand.
private void LoadConnectionsGrid()
{
DataGridViewComboBoxColumn typeCol =
(DataGridViewComboBoxColumn)dataGridViewConnections.Columns["ConnectionType"];
var qry = from c in _dc.ConnectionType
select c.Type;
typeCol.DataSource = qry;
dataGridViewConnections.Rows.Clear();
foreach (Connection conn in _dc.Connection.Include("ConnectionType"))
{
dataGridViewConnections.Rows.Add(conn.Name,
conn.ConnectionType.Type, conn.ConnectionString);
}
}

Resources