I use XtraTreeList control.
There are 2 columns: first for text and second for icon
Problem : I can't change default icon (zero index in corresponding imagelist). There are 3 images in imagelist.
For example I need to show icon which is located at 2 index
Code
TreeListColumn col = treeList1.Columns.Add();
col.Caption = "Text";
col.Visible = true;
TreeListColumn colImage = treeList1.Columns.Add();
colImage.Caption = "ImageColumn";
colImage.Visible = true;
RepositoryItemImageEdit imageEdit = new RepositoryItemImageEdit();
imageEdit.Images = imageList;
treeList1.RepositoryItems.Add(imageEdit);
colImage.ColumnEdit = imageEdit;
treeList1.BeginUnboundLoad();
TreeListNode node = treeList1.AppendNode(new object[] { "trololo", 2}, null);
node.SetValue(colImage.AbsoluteIndex, 2);
treeList1.EndUnboundLoad();
Thanks for everybody
Using RepositoryItemPictureEdit solved my problem. A little bit complex, but works
TreeListColumn col = treeList1.Columns.Add();
col.Caption = "Text";
col.Visible = true;
TreeListColumn colImage = treeList1.Columns.Add();
colImage.Caption = "ImageColumn";
colImage.Visible = true;
RepositoryItemPictureEdit imageEdit = new RepositoryItemPictureEdit();
imageEdit.ShowMenu = false;
treeList1.RepositoryItems.Add(imageEdit);
colImage.ColumnEdit = imageEdit;
treeList1.BeginUnboundLoad();
Image img = imageList.Images[1];
Bitmap bmp = new Bitmap(img);
TreeListNode node = treeList1.AppendNode(new object[] { "trololo", bmp }, null);
treeList1.EndUnboundLoad();
This task should be implemented using slightly different approach. First, you should use the RepositoryItemImageComboBox and populate its Items property. Each item has value and ImageIndex. The TreeList will show in a cell image from the item whose value equals the cell value. Here is the code which should work for you:
TreeListColumn col = treeList1.Columns.Add();
col.Caption = "Text";
col.Visible = true;
TreeListColumn colImage = treeList1.Columns.Add();
colImage.Caption = "ImageColumn";
colImage.Visible = true;
RepositoryItemImageComboBox imageEdit = new RepositoryItemImageComboBox();
imageEdit.SmallImages = imageList;
for(int i = 0; i < 3; i++)
imageEdit.Items.Add(new ImageComboBoxItem(i, i)); // i.e. value and image index
treeList1.RepositoryItems.Add(imageEdit);
colImage.ColumnEdit = imageEdit;
treeList1.BeginUnboundLoad();
TreeListNode node = treeList1.AppendNode(new object[] { "trololo", 2 }, null);
node.SetValue(colImage.AbsoluteIndex, 2);
treeList1.EndUnboundLoad();
Related
i have got dategrid which populated from sql query
HPEntities db = new HPEntities();
var queryTable4 = db.Database.SqlQuery<Lbrctn>("select * from Lbrctn");
var u = queryTable4.ToList();
DG_Example.ItemsSource = u;
i want to get the values of those row of my dataGrid which has checked. and send to Stored Procedure
so i try this code:
for (int i = 0; i < DG_Example.Items.Count - 1; i++)
{
mChkBox = DG_Example.Columns[0].GetCellContent(DG_Example.Items[i]) as CheckBox;
if (mChkBox.IsChecked == true)
{
var DaSelect = DG_Example.Columns[1].GetCellContent(DG_Example.Items[i]) as TextBlock;
var MNameTBk = DG_Example.Columns[2].GetCellContent(DG_Example.Items[i]) as TextBlock;
var ChiCodeTBk = DG_Example.Columns[3].GetCellContent(DG_Example.Items[i]) as TextBlock;
var ChiNameTBk = DG_Example.Columns[4].GetCellContent(DG_Example.Items[i]) as TextBlock;
var IntenCodeTBk = DG_Example.Columns[6].GetCellContent(DG_Example.Items[i]) as TextBlock;
var PeDescTBk = DG_Example.Columns[7].GetCellContent(DG_Example.Items[i]) as TextBlock;
db.sp_Ins_inten // using Stored Procedure
(
IntenCodeTBk.Text.Trim(),
MNameTBk.Text.Trim(),
Convert.ToInt32(chiCodeTBk.Text.Trim()),
ChiNameTBk.Text.Trim(),
PeDescTBk.Text.Trim(),
DaSelect.Text.Trim()
);
db.SaveChanges();
}
}
is there a better way than GetCellContent to get values of datagrid row I could use?
thanx in advance
all values can be found in a data item, displayed in a DataGridRow (except probably CheckBox, which is likely not bound):
for (int i = 0; i < DG_Example.Items.Count - 1; i++)
{
mChkBox = DG_Example.Columns[0].GetCellContent(DG_Example.Items[i]) as CheckBox;
if (mChkBox.IsChecked == true)
{
Lbrctn item = DG_Example.Items[i] as Lbrctn;
db.sp_Ins_inten // using Stored Procedure
(
item.IntenCodeTBk,
item.MNameTBk,
item.Convert,
item.ChiNameTBk,
item.PeDescTBk,
item.DaSelect
);
db.SaveChanges();
}
}
I'm having difficulty using a customlistrenderer class and homescreen class.
Here's my Homescreen class that contains the function generateData(), which is supposed to display a scroller of 22 buttons.
private function generateData(): void{
var list: List = new List();
list.width = 235;
list.height = 380;
list.name = "HomeScreenList";
this.addChild(list);
var rows:int = 6;
var iterator:int = 0;
var num:int = 22;
var counter:int = 0;
var obj:Object;
var heroName:Array = ["ana", "bastion", "d.va", "genji", "hanzo", "junkrat", "lucio",
"mccree", "mei", "mercy", "pharah", "reaper", "reinhardt", "roadhog", "soldier76", "symmetra",
"torbjorn", "tracer", "widowmaker", "winston", "zarya", "zenyatta"];
var temp:Array = []
obj = new Object();
while(iterator < rows){
obj.name1 = heroName[counter];
obj.image1 = myResource.getImage(heroName[counter]);
obj.name2 = heroName[counter+1];
obj.image2 = myResource.getImage(heroName[counter+1]);
obj.name3 = heroName[counter+2];
obj.image3 = myResource.getImage(heroName[counter+2]);
obj.name4 = heroName[counter+3];
obj.image4 = myResource.getImage(heroName[counter+3]);
temp.push(obj);
counter+4;
iterator++;
}
var collection:ListCollection = new ListCollection(temp);
//assign the renderer
list.itemRendererType = CustomMenuListRenderer;
list.dataProvider = collection;
list.addEventListener(Event.CHANGE, onChange);
this.addChild(list);
list.validate();
}
and the CustomMenuListRenderer class, under the initialize() function
super.initialize();
firstButton = new Button();
this.addChild(firstButton);
firstButton.x = 20;
firstButton.y = 100;
firstButton.scale = 0.60;
secondButton = new Button();
secondButton.x = 92;
secondButton.y = 100;
secondButton.scale = 0.60;
thirdButton = new Button();
thirdButton.x = 163;
thirdButton.y = 100;
thirdButton.scale = 0.60;
fourthButton = new Button();
fourthButton.x = 235;
fourthButton.y = 100;
fourthButton.scale = 0.60;
firstButton.addEventListener(Event.TRIGGERED, onTrigger);
secondButton.addEventListener(Event.TRIGGERED, onTrigger);
thirdButton.addEventListener(Event.TRIGGERED, onTrigger);
fourthButton.addEventListener(Event.TRIGGERED, onTrigger);
The problem is since the loop displays the 4 buttons each loop, an error occurs at the 23rd button(since I only specified 22 buttons but I declared 4 buttons on the CustomMenuListRenderer class) in the 6th row.
My question is how do I fix this issue?
First question, why define num manually and not use heroName.lenght? Is more secure
var heroName:Array = ["ana", "bastion", "d.va", "genji", "hanzo", "junkrat", "lucio",
"mccree", "mei", "mercy", "pharah", "reaper", "reinhardt", "roadhog", "soldier76", "symmetra",
"torbjorn", "tracer", "widowmaker", "winston", "zarya", "zenyatta"];
var num:int = heroName.lenght;
To fix your error, you have to check is heroName index exists before to get it.
Something like :
obj = new Object();
while(iterator < rows){
var objCounter:int = 1;
while(objCounter <= 4 )
{
if( counter < heroName.lenght )
{
obj["name"+objCounter] = heroName[counter];
obj["image"+objCounter] = myResource.getImage(heroName[counter]);
}
objCounter++;
counter++;
}
temp.push(obj);
iterator++;
}
i am having arraylist.let say it contains 15 elements. I am adding these to stack panel. I need to add 3 elements per line. my code is below. I am getting either horizontal or verrtical.Let me know how to do this.
MainWindow w;
public ShopCart(MainWindow m,ArrayList _list)
{
InitializeComponent();
w = m;
int i = 1;
foreach (string cartitems in _list)
{
mystackpanel.Orientation = Orientation.Horizontal;
mystackpanel.Margin.Left.Equals(150);
Label lbl = new Label();
lbl.Name = "Label" + i;
lbl.Height = 30;
lbl.Width = 200;
lbl.Margin.Left.Equals(150);
//lbl.Margin.Top.Equals(150);
lbl.Content = cartitems.ToString();
mystackpanel.Children.Add(lbl);
i++;
int str = mystackpanel.Children.Count;
MessageBox.Show(Convert.ToString(str));
if (str%3 == 0)
{
Button btndelete = new Button();
btndelete.Content = "Delete";
btndelete.Width = 120;
btndelete.Height = 35;
mystackpanel.Children.Add(btndelete);
mystackpanel.Margin.Top.Equals(500);
}
}
Here is some sample code(assuming you already have a list of buttons, and will add outer stack panel to your main control) you can try, you may need to change few things as per your need:
List<Button> buttons = new List<Button>();
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Horizontal;
int count = 0;
StackPanel innerPanel = new StackPanel();
innerPanel.Orientation = Orientation.Vertical;
foreach (Button button in buttons)
{
innerPanel.Children.Add(button);
++count;
if (count % 3 == 0 && count != 0)
{
panel.Children.Add(innerPanel);
innerPanel = new StackPanel();
innerPanel.Orientation = Orientation.Vertical;
}
}
if (panel.Children.Contains(innerPanel) == false)
{
panel.Children.Add(innerPanel);
}
Although in my opinion the best way will be to have a Grid with n*n row and columns and add your buttons to respective row, columns.
im trying to create a randomized array that will change the position of my pictures(in the tilelist) each time the application is launched. Hope you understand what im looking for, and i dont really understand how to link code correctly here :/
I think its easier simply copying into flash and view from there
thanks :)
Here's my code:
flash.events.MouseEvent;
btn_back.addEventListener(MouseEvent.CLICK, ftilbake);
function ftilbake(evt:MouseEvent)
{
gotoAndStop(1);
}
var heroArray:Array = new Array();
var randomizeArray:Array = new Array();
createArrays()
function createArrays()
{
heroArray[0] = new Array("Rumble","Garen","Lulu","Corki","Warwick");
heroArray[1] = new Array("Bilder/Champions/Rumble.jpg","Bilder/Champions/Garen.jpg","Bilder/Champions/Lulu.jpg","Bilder/Champions/Corki.jpg","Bilder/Champions/Warwick.jpg");
heroArray[2] = new Array("Bilder/Champions/Rumble1.jpg","Bilder/Champions/Garen1.jpg","Bilder/Champions/Lulu1.jpg","Bilder/Champions/Corki1.jpg","Bilder/Champions/Warwick1.jpg");
heroArray[3] = new Array("the Mechanized Menace","the Might of Demacia","the Fae Sorceress","the Daring Bombardier","the Blood Hunter");
heroArray[4] = new Array(0,0,0,0,0);
heroArray[5] = new Array("Rumble.wav","Garen.wav","Lulu.wav","Corki.wav","Warwick.wav");
randomizeArray[0] = new Array();
randomizeArray[1] = new Array();
randomizeArray[2] = new Array();
randomizeArray[3] = new Array();
randomizeArray[4] = new Array();
//randomizing the positions in the array(?)
var randomPos:int = 0;
for (var i:int = 0; i < heroArray.length; i++)
{
randomPos = int(Math.random() * heroArray[0].length);
while (randomizeArray[randomPos][0] != null)
{
randomPos = int(Math.random() * heroArray.length);
}
}
}
var totalKlikk:int = 0;
for (var teller1:int = 0; teller1 <heroArray[0].length; teller1++)
{
leagueChamps.addItem({label:heroArray[0][teller1], source:heroArray[1][teller1]});
}
leagueChamps.columnWidth = 80;
leagueChamps.rowHeight = 80;
leagueChamps.columnCount = 5;
leagueChamps.rowCount = 1;
leagueChamps.direction = "horizontal";
leagueChamps.addEventListener(MouseEvent.CLICK, bildeKlikk);
function bildeKlikk(evt:MouseEvent)
{
var element:Object = leagueChamps.selectedItem;
var fil:String = element.source;
txtChHero.visible = false;
totalKlikk++;
if (totalKlikk <11)
{
for (teller1 = 0; teller1 <heroArray[0].length; teller1++)
{
if (heroArray[1][teller1] == fil)
{
heroArray[4][teller1]++;
if (heroArray[4][teller1] == 1)
{
txtBox1.visible = true;
txtBox2.visible = true;
leagueShow.source = heroArray[2][teller1];
txtBox1.text = heroArray[0][teller1];
txtBox2.text = heroArray[3][teller1];
}
if (heroArray[4][teller1] == 2)
{
txtBox1.visible = true;
txtBox2.visible = true;
leagueShow.source = heroArray[2][teller1];
txtBox1.text = heroArray[0][teller1];
txtBox2.text = heroArray[3][teller1];
heroArray[5][teller1].play();
}
if (heroArray[4][teller1] == 3)
{
bildeKlikk3();
}
}
}
}
else
{
txtChHero.visible = true;
txtChHero.text = "Du har klikket følgende mange ganger på de forskjellige bildene:";
txtH1.text = heroArray[4][0]
txtH2.text = heroArray[4][1]
txtH3.text = heroArray[4][2]
txtH4.text = heroArray[4][3]
txtH5.text = heroArray[4][4]
txtBox1.visible = false;
txtBox2.visible = false;
leagueShow.visible = false;
}
}
function bildeKlikk3()
{
txtBox1.visible = true;
txtBox2.visible = true;
leagueShow.source = heroArray[2][teller1];
txtBox2.text = "Ikke mer informasjon";
}
txtBox2.visible = false;
txtBox1.visible = false;
Array randomization is something which comes up very frequently in all my projects so I ended up creating a static method in my Array utility class for it.
It uses the Fisher–Yates shuffle which is supposed to be the most unbiased (and efficient?) algorithm for shuffling the content of an array. There could be faster ways of doing it (like using the array.sortOn() method, but I am not sure how unbiased a result they get compared to this one.)
The shuffle method:
/**
* shuffle the given array
* #param array
* #return
*/
public static function shuffle(array:Array):Array
{
var index :int;
var item :*;
var limit :int = array.length as int;
for (var i:int = limit-1; i >= 0 ; --i)
{
index = Math.floor(Math.random() * (i + 1));
item = array[index];
array[index] = array[i];
array[i] = item;
}
return array;
}
Example:
var myArray:Array = new Array("Red","Orange","Yellow","Green","Blue");
myArray = ArrayUtils.shuffle(myArray);
where ArrayUtils is the name of the Array Utility class I use. You can simply use the function directly if you don't want to use a utility class of course.
Try this
while (heroArray.length > 0) {
randomizeArray.push(heroArray.splice(Math.round(Math.random() * (heroArray.length - 1)), 1)[0]);
}
Just instatiate randomizeArray though, and don't fill it with empty Arrays like in ur source!
I recommend creating a single object to hold related data, and using a single Array/Vector of that object type.
To answer your question, randomizing an array is fairly easy to do with array.sort() and a random selection function. This method can also be used to randomize any array. you don't need to splice arrays or iterate either.
function sortOnRandom(a:Object, b:Object):Number{
if(Math.random() > 0.5){
return 1;
}else{
return -1;
}
}
myArray.sort(sortOnRandom);
I am using DataGridView ,in which I have dynamically created an Image Column ,I want to diplay Pass and fail Images in this column depeending on the condition below is the code,
DataGridViewImageColumn img = new DataGridViewImageColumn();
img.Name = "img";
img.HeaderText = "Image Column";
dataGridView1.DataSource = dt;
dataGridView1.Columns.Add(img);
int number_of_rows = dataGridView1.RowCount;
for (int i = 0; i < (number_of_rows - 1); i++)
{
if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "Pass")
{
Image image = global::Instore.Properties.Resources.pass;
img.Image = image;
dataGridView1.Rows[i].Cells["img"].Value = image;
}
else if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "Fail")
{
Image image2 = global::Instore.Properties.Resources.fail;
img.Image = image2;
dataGridView1.Rows[i].Cells["img"].Value = image2;
}
}
I have attach the code when I am running it its showing Pass.png in all the rows whereas it should show fail image in some of the rows..
Kindly help...
Thanks
Sneha
Remove these two lines:
img.Image = image;
...
img.Image = image2;