how to maintain datatable for grid with in a grid - datatable

I'm working with grid within a grid. I want to maintain dt. I don't understand how to maintain child grid in datatable please help me.
for (int jj = 0; jj < grvQuestions.Rows.Count; jj++)
{
DataRow dr;
GridViewRow row = grvQuestions.Rows[jj];
dr = dtval.NewRow();
for (int ii = 0; ii < row.Cells.Count; ii++)
{
dr[ii] = row.Cells[ii].Text;
}
dtval.Rows.Add(dr);
}
I tried to import data but this didn't work.

Related

How to set a number string into a real string formation?

I'm now using NPOI to cope with Excel export, and here's my codes (part in .NET):
int rowIndex = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
IRow dataRow = sheet.CreateRow(rowIndex);
for (int j = 0; j < cellCount; j++)
{
cell = dataRow.CreateCell(j,CellType.String);
cell.SetCellValue(new HSSFRichTextString(dt.Rows[i][j].ToString()));
}
rowIndex++;
}
What makes me feel surprised is there's a list whose number string is "20150525", and it will be analyzed as "2015……E+10" formation (scientific number formation). However I wanna keep it as a string value. So How?
Thanks!
In fact we have to set a CellStyle, snippet of sample codes is below:
IRow row = book[0].CreateRow(rowIndex + 1);
ICell rowCell = null;
rowCell = row.CreateCell(colIndex);
rowCell.SetCellValue(realCellValue);
ICellStyle cellStyle = book.CreateCellStyle();
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#");
rowCell.CellStyle = cellStyle;

how to get screen coords using projection with a multipolygon in d3

I am using D3 to display customer location within counties. For MOST of my counties I am not having any problems. I am using the following code snippet to get the XY coordinates for my counties
var countyCoords = county.geometry.coordinates[0];
...
for (var j = 0; j < countyCoords.length; j++)
{
var x = projection(countyCoords[j])[0];
var y = projection(countyCoords[j])[1];
Works like a charm, with one exception. If my county.geometry["type"] is a MultiPolygon, these lines fail. How do I get the screen locations (i.e. x,y) of a MultiPolygon in d3?
Here are some lines from my input to d3.json() [edited for display here]
"counties":
{
"type":"GeometryCollection",
"geometries":[
{"type":"MultiPolygon","properties":{"NAME":"Chester"},"id":"Chester","arcs":[[[13,2111,15,2112,17,18,2113,2114,20,2115,2116,-1951,2117,2118,2119,9,2120,11,2121]],[[2122,2123]]]},
{"type":"Polygon","properties":{"NAME":"Clarion"},"id":"Clarion","arcs":[[-1966,2124,-2004,-2018,-2063]]},
I get the counties by using this line:
counties = topojson.feature(topoData, topoData.objects.counties);
I iterate through the counties and collect the XY locations mentioned above like this:
for (var i = 0; i < counties.features.length; i++)
{
var county = counties.features[i];
var countyCoords = county.geometry.coordinates[0];
var xy = [];
for (var j = 0; j < countyCoords.length; j++)
{
var x = projection(countyCoords[j])[0];
var y = projection(countyCoords[j])[1];
var dataPoint = [x,y];
xy.push(dataPoint);
}
county.properties["XY"] = xy;
}
This works correctly for the county "Clarion" but fails for the county "Chester".
A GeoJSON multipolygon has an additional array level to its structure that you'd need to iterate through:
http://geojson.org/geojson-spec.html
To account for this, you'd have to do something like this:
if (county.geometry.type == "MultiPolygon") {
for (var x=0; x< countyCoords.length;x++) {
for (var j = 0; j < countyCoords[x].length; j++) {
var x = projection(countyCoords[x][j])[0];
var y = projection(countyCoords[x][j])[1];
Here is the code to solve my problem. It is pretty much the suggestion of Elijah but tailored to my specific needs. (Note: this is only for Multipolygon types, normal polygon types should use the code identified in my original post). Also, please feel free to point out anywhere where my code can be improved.
for (var i = 0; i < counties.features.length; i++)
{
var county = counties.features[i];
if (county.geometry["type"] === "MultiPolygon")
{
var xy = [];
for (var k = 0; k < county.geometry.coordinates.length; k++)
{
var countyCoords = county.geometry.coordinates[k][0];
for (var j = 0; j < countyCoords.length; j++)
{
var x = projection(countyCoords[j])[0];
var y = projection(countyCoords[j])[1];
var dataPoint = [x,y];
xy.push(dataPoint);
}
county.properties["XY"] = xy;
}
}
}

modifying the lengthY of some cubes is slow

I want to write a 3d version of a fft. (Like this:https://wiki.mozilla.org/File:Fft.png)
So I created a few bars and in an outside function, my first aproach was to set the lengthY to a value. Then I call bar.modified() to force it to be repainted.
If I now use more than 50 bars, it is horrible slow (on my 4 core CPU). I guess there's a better way to do it, right?
Source:
var elements = new Array();
create3d = function(len) {
var r = new X.renderer3D();
r.init();
if(a.length == 0){
for ( var y = 0; y < len; y++) {
var c = new X.cube();
a.push(c);
}
}
for ( var i = 0; i < len; i++) {
a[i].center = [i*2 , 0, 0];
a[i].lengthX = 1;
a[i].lengthY = 20;
a[i].lengthZ = 1;
a[i].color = [i%2,0,0];
r.add(a[i]);
}
r.render();
};
function setVal(index,val){
var element = a[index];
element.lengthY = val;
element.modified();
}
I created a JSFiddle on how to do that and it is pretty fast for 1000 cubes
http://jsfiddle.net/haehn/6fVRC/

add custom clickable buttons

I am developing an app for win phone 7. In that I need to add clickable buttons(not specific number) into a grid dynamically.and navigate the page with some information to other page.
can any body help me please....
private void buildThumbs(Grid gridThumb, int p) {
int n;
if (p % 3 == 0)
n = p / 3;
else
n = (p / 3) + 1;
GridLength height = new GridLength(100);
for (int i = 0; i < n; i++)
{
RowDefinition rowDef = new RowDefinition();
rowDef.MinHeight = 100;
gridThumb.RowDefinitions.Add(rowDef);
}
MovieThumb[,] thumb = new MovieThumb[n, 3];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 3; j++)
{
Image ni=new Image();
ImageSourceConverter ims = new ImageSourceConverter();
ni.SetValue(Image.SourceProperty ,ims.ConvertFromString( "/Images/book1.png"));
thumb[i, j].SetValue(Grid.ColumnProperty, j);
thumb[i,j].SetValue(Grid.RowProperty,i);
thumb.Click += new RoutedEventHandler(thumb_click("sandy"));
thumb[i, j].CoverImage = ni;
thumb[i, j].Loading = "Loading";
thumb[i, j].progress = false;
gridThumb.Children.Add(thumb);
}
}
}
I am not quite sure if I understand your problem, but if you want to set the Column and Row number for your dynamically created buttons, you may do so with Grid.SetColumn(buttonname, column); Grid.SetRow(buttonname, row); before you add the object to the gridThumb.
We need some more information for what exactly you want to accomplish and what doesn't work for you to help :)

Creating a new JTable from current JTable view

I am working on a project that involves JTable and performing sorting and filtering operations on it. I am done with the sorting and filtering part and now I want to be able to create a new table from the current view of older table.
e.g. If I apply certain filters to my old table, some rows are filtered out. I don't want those filtered out rows in my new table. I figured that I can convert the new row indices to model indices and add the cell values manually to new table's model, but I was wondering if there's any other efficient way to do this?
Following is what I ended up doing:
//this code block will print out the rows in current view
int newRowCount = table.getRowCount();
int newColumnCount = table.getColumnCount();
for (int i = 0; i < newRowCount; i++) {
for (int j = 0; j < newColumnCount; j++) {
int viewIndex = table.convertRowIndexToModel(i);
String value = (String) model.getValueAt(viewIndex, j);
System.out.print(value + "\t");
}
System.out.println();
}
no need for any index conversion, simply ask query the table instead of the underlying model
for (int i = 0; i < table.getRowCount(); i++) {
for (int j = 0; j < table.getColumnCount(); j++) {
Object value = table.getValueAt(i, j);
System.out.print(value + "\t");
}
}
Note: better rename the i/j to row/column for readability, was too lazy ;-)

Resources