Add New Row in GridView winform on Button Click - c#-4.0

Add New Row in GridView winform on Button Click.
Need to have single button in grid rather than DataGridViewButtonColumn

you can add it by using
GridView1.DataSource = datatable;
and then add new row by this
datatable.Rows.Add();
this will add new row and give control id into add().

use this
public partial class Form1 : Form
{
Button textBoxDgv1 = new Button();
Label labelDgv1 = new Label();
the next is on the Form_Load event
private void Form1_Load(object sender, EventArgs e)
{
labelDgv1.Text = "Delete";
labelDgv1.Height = 20;
labelDgv1.AutoSize = false;
labelDgv1.BorderStyle = BorderStyle.FixedSingle;
labelDgv1.TextAlign = ContentAlignment.MiddleCenter;
int Xdgv1 = this.dataGridView1.GetCellDisplayRectangle(2, -1, true).Location.X;
labelDgv1.Width = this.dataGridView1.Columns[2].Width + Xdgv1;
labelDgv1.Location = new Point(0, this.dataGridView1.Height - textBoxDgv1.Height);
this.dataGridView1.Controls.Add(labelDgv1);
and one more section is in dataGridView1_CellPainting
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
int sum = 0;
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[3].Value != string.Empty)
{
sum += Convert.ToInt32(this.dataGridView1[3, i].Value);
}
}
textBoxDgv1.Text = sum.ToString();
int Xdgvx = this.dataGridView1.GetCellDisplayRectangle(2, -1, true).Location.X;
labelDgv1.Width = this.dataGridView1.Columns[2].Width + Xdgvx;
labelDgv1.Location = new Point(0, this.dataGridView1.Height - textBoxDgv1.Height);
textBoxDgv1.Width = this.dataGridView1.Columns[3].Width;
Xdgvx = this.dataGridView1.GetCellDisplayRectangle(3, -1, true).Location.X;
textBoxDgv1.Location = new Point(Xdgvx, this.dataGridView1.Height - textBoxDgv1.Height);
}

Related

Control Validating issue when WPF control hosted in ElementHost is clicked on WinForm Application

I have a winform application on which there is a mix of Winform and a WPF control hosted on ElementHost. When the winform textbox goes into Validating because the WPF control is clicked, and there is validating error, the ElementHost keeps firing Focus event which makes my application stuck.
Please advice if there is a way to resolve it.
I have created a sample application to replicate the issue.
I have a Form1 containing 2 winform textboxes (textbox1, textbox2) and a WPF control hosted on ElementHost.
textbox1_validating event handler checks if input is not "1", then the event is cancelled by setting the event argument e.Cancel to true. This works well if textbox1 goes into validating because other winform control is clicked.
However, if textbox1 goes into validating due to WPF control gains focus, the cancel event does not work. ElementHost keeps firing Focus event causing textbox1_validating been called again and again.
UserControl Code:
<UserControl x:Class="WpfControlLibrary1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="54" d:DesignWidth="295" >
<Grid Height="43">
<TextBox Height="20" HorizontalAlignment="Left" Name="textBox1" VerticalAlignment="Top" Width="106" Text="Default1" />
<TextBox Height="20" HorizontalAlignment="Left" Margin="130,0,0,0" Name="textBox2" VerticalAlignment="Top" Width="73" Text="Default2" />
</Grid>
WinForm Code:
public partial class Form1 : Form
{
public static bool HasError = false;
public Form1()
{
InitializeComponent();
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if (textBox1.Text != "1" && textBox1.Text != "")
{
MessageBox.Show("Input is invalid, expecting \"1\". ");
HasError = true;
e.Cancel = true;
}
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this._durationCtrlHost = new WindowsFormsApplication1.DurationCtrlHost();
this._durationCtrl = new WpfControlLibrary1.UserControl1();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(120, 23);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(242, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter);
this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox1_Validating);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(121, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(240, 20);
this.textBox2.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(90, 13);
this.label1.TabIndex = 4;
this.label1.Text = "WinformTextbox1";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(25, 63);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(90, 13);
this.label2.TabIndex = 5;
this.label2.Text = "WinformTextbox2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(24, 104);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 13);
this.label3.TabIndex = 6;
this.label3.Text = "WPFControl";
//
// _durationCtrlHost
//
this._durationCtrlHost.Location = new System.Drawing.Point(120, 90);
this._durationCtrlHost.Name = "_durationCtrlHost";
this._durationCtrlHost.Size = new System.Drawing.Size(271, 60);
this._durationCtrlHost.TabIndex = 3;
this._durationCtrlHost.Child = this._durationCtrl;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(420, 282);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this._durationCtrlHost);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
}
public class DurationCtrlHost : ElementHost
{
private const int WM_SETFOCUS = 0x0007;
private const int WM_KILLFOCUS = 0x0008;
private int SetFocusFiredCount = 0;
private int KillFocusFiredCount = 0;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SETFOCUS)
{
SetFocusFiredCount++;
if (Form1.HasError)
return;
}
else if (m.Msg == WM_KILLFOCUS)
{
KillFocusFiredCount++;
}
base.WndProc(ref m);
}
}

Collecting data from People Picker

I want to Collect the usernames added in the PeoplePicker and display them in the textbox on the click of "Add" button for a custom aspx page.
I tried many codes but its not working.
Here is my code:
protected void btnpicker_Click(object sender, EventArgs e)
{
for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
{
PickerEntity picker = (PickerEntity)userPicker.ResolvedEntities[i];
Hashtable hstEntityData = picker.EntityData;
string accountName = Convert.ToString(hstEntityData["AccountName"]);
txtPicker.Text = "Count" + hstEntityData.Count.ToString();
txtPicker.TextMode = TextBoxMode.MultiLine;
}
}
Help Highly Appreciated.
Try the following code.
protected void btnpicker_Click(object sender, EventArgs e)
{
for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
{
PickerEntity picker = (PickerEntity)userPicker.ResolvedEntities[i];
yourTextBox.Text = "Count: " + new SPFieldUserValue(yourSPWebObject, Convert.ToInt32(picker.EntityData["SPUserID"]), picker.Key).User.Name;
}
}
This code will give all name of the users in your textbox.

How can i refer to a textbox that i don't know it's name?

I'm using VC++ 2008 (Windows Form Application C++\CLR), I created dynamic array of textboxes (the user defines how many textboxes he wants to create), and i want to make a KeyPress event handler, in order to prevent Chars (i want these textboxes to be numerical only, and accept only one dot "for decimal numbers"). So how can I refer to the textbox that the user is using (the textbox that the cursor on for example) is there any way i can do this? The function looks like:
private: System::Void textBox_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
if(e->KeyChar == '.')
{
if(this->/*the textbox in use*/->Text->Contains(".") && !this->/*the textbox in use*/->SelectedText->Contains("."))
e->Handled = true;
}
else if(!Char::IsDigit(e->KeyChar) && e->KeyChar != 0x08)
e->Handled = true;
}
private void CreateTextBoxControls()
{
intColCount= Convert.ToInt32(txtColumnNo.Text.ToString().Trim());
int rowCount =0;
Table tblHead = new Table();
if (tblHead.GetType().ToString().Equals("System.Web.UI.WebControls.Table") && PHOptions.FindControl("tblHead") == null )
{
tblHead.ID = "tblHead";
tblHead.EnableViewState = true;
tblHead.BorderWidth=Unit.Pixel(0);
tblHead.CellSpacing = 0;
tblHead.CellPadding = 1;
tblHead.Width = Unit.Percentage(96);
TableRow rH = new TableRow();
TableCell cH = new TableCell();
cH.Text= "Table Heading" ;
cH.Font.Bold = true;
rH.Cells.Add(cH);
tblHead.Rows.Add(rH);
PHOptions.Controls.Add(tblHead);
if(intColCount>0)
rH.Visible =true;
else
rH.Visible =false;
}
Table tblHelp = new Table();
if (tblHelp.GetType().ToString().Equals("System.Web.UI.WebControls.Table") && PHOptions.FindControl("tblHelp") == null )
{
tblHelp.ID = "tblHelp";
}
tblHelp.EnableViewState = true;
tblHelp.BorderWidth=Unit.Pixel(1);
tblHelp.CellSpacing = 0;
tblHelp.CellPadding = 1;
tblHelp.BorderWidth = Unit.Pixel(1);
tblHelp.Width = Unit.Percentage(96);
for (int rowIndex=0; rowIndex<=rowCount; rowIndex++)
{
TableRow r = new TableRow();
TableRow rWeight= new TableRow();
//r.ID = "rLabel";
TableRow rID = new TableRow();
for (int clIndex=0; clIndex<intColCount; clIndex++)
{
TableCell c = new TableCell();
txtBox = new TextBox();
if (txtBox.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") && PHOptions.FindControl("txtOption"+(clIndex+1).ToString()) == null )
{
txtBox.ID ="txtOption"+(clIndex+1).ToString();
//txtBox.Text = (clIndex+1).ToString();
txtBox.Width= Unit.Pixel(45);
txtBox.MaxLength = 2;
c.BorderWidth=Unit.Pixel(1);
c.Width=Unit.Pixel(80);
c.Controls.Add(txtBox);
r.Cells.Add(c);
txtBox.PreRender += new System.EventHandler(this.txtBox_PreRender);
}
}
tblHelp.Rows.Add(r);
}
TableRow rSubmit = new TableRow();
TableCell cSubmit = new TableCell();
cSubmit.ColumnSpan = intColCount ;
btnSubmitButton = new Button();
btnSubmitButton.ID ="btnSubmit";
btnSubmitButton.Text= "Submit";
if( PHOptions.FindControl("btnSubmit") == null )
cSubmit.Controls.Add(btnSubmitButton);
cSubmit.Attributes.Add("Align","Center");
rSubmit.Cells.Add(cSubmit);
tblHelp.Rows.Add(rSubmit);
PHOptions.Controls.Add(tblHelp);
this.btnSubmitButton.PreRender += new System.EventHandler(this.btnSubmitButton_PreRender);
this.btnSubmitButton.Click += new System.EventHandler(this.btnSubmitButton_Click);
}
private void btnSubmitButton_Click(object sender, System.EventArgs e)
{
for (int clIndex=0; clIndex<intColCount; clIndex++)
{
string boxName = "txtOption" + (clIndex+1).ToString();
TextBox tb = PHOptions.FindControl(boxName) as TextBox;
if( lblDisplay.Text != "" )
lblDisplay.Text+=","+tb.Text ;
else
lblDisplay.Text=tb.Text ;
}
}
Just refer this code ...
(this contains both for creating textbox dynamically and read from textbox)

Change image after each 10seconds in WPF image box

There is a requirement of updating image in image boxes of WPF. I am thinking of creating a list with all the paths and then using a timer control checking the 10 seconds. After the 10 seconds has elapsed the next id from list is taken and bound to the image box. I am new to WPF. Can any one help me with a working example.
Use a DispatcherTimer to invoke a method at regular intervalls. In this method change the bound image, remember to raise the INotifyPropertyChanged event to let WPF know it should query the bound property again.
Hi i have made thig running with the below code .
private void timer_Elapsed(object sender,System.Timers.ElapsedEventArgs e)
{
Action action1 = () => this.BeginStoryboard((Storyboard)this.FindResource("BlinkStoryboardFed"));
Dispatcher.BeginInvoke(action1);
Action action = () => BindToImages(lststr);
Dispatcher.BeginInvoke(action);
//BindToImages(lststr);
_timer.Start();
}
public void BindToImages(List<string> lststrpath)
{
lock (_locker)
{
for (int i = 0; i < lststrpath.Count; i++)
{
if (count == 0)
{
startindex = i;
this.BindToImgIndx = startindex;
AppState.Index = i;
BitmapImage img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(lststrpath[startindex].ToString(), UriKind.Relative);
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
image1.Source = img;
count++;
}
else
{
int k = AppState.Index;
k = ++k;
this.BindToImgIndx = startindex;
if (k < lststrpath.Count)
{
BitmapImage img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(lststrpath[k].ToString(), UriKind.Relative);
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
image1.Source = img;
}
AppState.Index = k;
}
this.BeginStoryboard((Storyboard)this.FindResource("BlinkStoryboardUnFed"));
break;
}
}
}

Why the Dialog is not shown in this situation?

I want to display a Dialog when I click on a userdefined component that I have created : I named its class name to ListBox. I want to simulate a LWUIT ComboBox with my user defined component which will accepts the blank area ; because LWUIT ComboBox doesn't accept the blank area.
The problem is that when my ListBox is at a coordinate such that there is no more space below it to display the Dialog then the Dialog is not shown ; but if there are more space below then the Dialog is shown.
Here is the captured image when the Dialog is not shown :
In the captured image the user defined ListBox is the component just above the two Buttons at the bottom of the phone screen.
And here are the codes :
public class ListBox extends Container implements ActionListener
{
private Container cListBox = new Container(new BorderLayout());
private Label[] tLabel;
private int[] tLabelW;
private int largestLabelW;
private Label libelle = new Label();
private Label arrow = new Label((MenuPrincipalForm.r).getImage("listboxarrow"));
private int preferredWidth, preferredHeight, screenWidth, screenHeight;
private Vector vData = new Vector();
private final int leftPadding = 3;
private CListCellListBox listRenderer;
private List list;
private Dialog dialog;
private String selectedData;
public ListBox(String[] lData, int prefHeight, int formWidth, int formHeight, int topMargin, int bottomMargin)
{
super(new FlowLayout(Component.CENTER));
setFocusable(true);
screenWidth = formWidth;
screenHeight = formHeight;
tLabel = new Label[lData.length + 1];
tLabelW = new int[lData.length + 1];
for (int i = 0 ; i < lData.length + 1 ; i++)
{
if (i < lData.length)
{
vData.addElement(new String(lData[i]));
tLabel[i] = new Label(lData[i]);
tLabelW[i] = tLabel[i].getPreferredW();
}
else
{
vData.addElement(new String(""));
tLabel[i] = new Label("");
tLabelW[i] = 0;
}
}
largestLabelW = Comparator.max(tLabelW);
preferredWidth = leftPadding + largestLabelW + arrow.getPreferredW();
preferredHeight = prefHeight - 2 ;
selectedData = String.valueOf(vData.lastElement());
libelle.setText(String.valueOf(vData.lastElement()));
libelle.setTextPosition(Label.LEFT);
libelle.setPreferredW(preferredWidth);
libelle.setPreferredH(preferredHeight);
arrow.setAlignment(Label.CENTER);
arrow.setPreferredH(preferredHeight);
listRenderer = new CListCellListBox(false);
list = (new CList(vData, false)).createList(listRenderer, this);
list.setItemGap(0);
list.setSelectedIndex(vData.indexOf(vData.lastElement()));
list.getUnselectedStyle().setPadding(0, 0, 0, 0);
list.getSelectedStyle().setPadding(0, 0, 0, 0);
list.setPreferredW(leftPadding+preferredWidth+arrow.getPreferredW());
dialog = new Dialog();
dialog.setScrollableY(false);
dialog.getContentPane().getSelectedStyle().setPadding(0, 0, leftPadding, 0);
dialog.getContentPane().getUnselectedStyle().setPadding(0, 0, leftPadding, 0);
dialog.addComponent(list);
cListBox.addComponent(BorderLayout.WEST, libelle);
cListBox.addComponent(BorderLayout.EAST, arrow);
cListBox.setPreferredH(preferredHeight);
getUnselectedStyle().setPadding(Component.LEFT, leftPadding);
getSelectedStyle().setPadding(Component.LEFT, leftPadding);
getUnselectedStyle().setBorder(Border.createLineBorder(1));
getSelectedStyle().setBorder(Border.createLineBorder(1));
addComponent(cListBox);
setPreferredH(preferredHeight);
getUnselectedStyle().setMargin(Component.TOP, topMargin);
getSelectedStyle().setMargin(Component.TOP, topMargin);
getUnselectedStyle().setMargin(Component.BOTTOM, bottomMargin);
getSelectedStyle().setMargin(Component.BOTTOM, bottomMargin);
}
public void actionPerformed(ActionEvent ae)
{
if ( (ae.getSource() instanceof List) && ((List)ae.getSource()).equals(list) )
{
dialog.dispose();
if (list.getSelectedItem() instanceof Content)
{
Content valeur = (Content)list.getSelectedItem();
selectedData = valeur.getEnreg();
libelle.setText(selectedData);
repaint();
}
}
}
public void setSelectedIndex(int idx)
{
list.setSelectedIndex(idx);
selectedData = String.valueOf(vData.elementAt(idx));
libelle.setText(String.valueOf(vData.elementAt(idx)));
repaint();
}
public String getSelectedData()
{
return selectedData;
}
public void pointerPressed(int x, int y)
{
int espaceVertRestant, top, bottom, left, right;
espaceVertRestant = screenHeight - ( libelle.getAbsoluteY() + preferredHeight );
if (espaceVertRestant > list.getPreferredH())
{
top = getAbsoluteY() + preferredHeight - 1 ;
bottom = screenHeight - ( getAbsoluteY() + preferredHeight + list.getPreferredH() ) ;
}
else
{
top = screenHeight - ( list.getPreferredH() + preferredHeight + espaceVertRestant ) ;
bottom = getAbsoluteY() ;
}
left = getAbsoluteX() ;
right = screenWidth - ( getAbsoluteX() + getPreferredW() );
dialog.show(top, bottom, left, right, false, true);
}
}
Here is the code of the Form where I add this ListBox component :
public class ModifierEcheanceForm extends Form implements ActionListener, DataChangedListener {
private VirtualKeyboard vkNombre = new VirtualKeyboard();
private String textFieldStatus, listBoxStatus;
private Container cntnr = new Container();
private Container c = new Container();
private Container c1 = new Container();
private Container c2 = new Container();
private Container c3 = new Container();
private Container c4 = new Container();
private Container c5 = new Container();
private Container c6 = new Container();
private Container c7 = new Container();
private Container c8 = new Container();
private Container c9 = new Container();
private Container c10 = new Container(new FlowLayout(Component.CENTER));
private Container cz1 = new Container();
private Container cz2 = new Container();
private Container cz3 = new Container();
private Container cz4 = new Container();
private Container cz5 = new Container();
private TextField t1=new TextField("zzz"),t2=new TextField("zzz"),t3=new TextField("zzz"),t4=new TextField("zzz"),t5=new TextField("zzz");
private Button modifierBtn, reset;
private BoxLayout bxl = new BoxLayout(BoxLayout.Y_AXIS);
private BoxLayout bxltx = new BoxLayout(BoxLayout.X_AXIS);
private boolean isMenuShown;
private Command annulerCmd;
private Command listeMenu, listeClientCmd, listeCreditCmd, ppalCmd;
private Command ficheMenu, backCmd;
private SmartPhoneBanking controler;
private Form backForm, OldbackForm;
private EcheanceDB echeancedb;
private Vector listecheance = new Vector();
private int idEcheance;
private Label echedatelbl, montantlbl, eche_payelbl, eche_retardlbl, ecehe_nbretardlbl, eche_crdlbl, eche_rembourselbl, eche_interetlbl,flagPayelbl;
private TextField echedatetxt, montanttxt, eche_payetxt, eche_retardtxt, ecehe_nbretardtxt, eche_crdtxt, eche_remboursetxt, eche_interettxt;
private ListBox flagPayetxt; // here is the ListBox
private CreditDB creditdb = new CreditDB();
private Vector listeCredit = new Vector();
private String idClient, idCredit;
public static int listEcheanceSelectedRow;
public ModifierEcheanceForm(SmartPhoneBanking ctrl, int idEcheance, Form prevForm)
{
super("Modification échéance");
vkNombre.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_SYMBOLS_MODE});
this.controler = ctrl;
this.idEcheance = idEcheance;
backForm = prevForm;
OldbackForm = FicheCreditForm.backForm;
echeancedb = new EcheanceDB();
listecheance = echeancedb.echeanceParId(String.valueOf(idEcheance));
idCredit = String.valueOf(listecheance.elementAt(5));
listeCredit = creditdb.listCredit(Integer.parseInt(idCredit));
idClient = String.valueOf(listeCredit.elementAt(12));
c.setLayout(bxl);
c1.setLayout(bxltx);
c2.setLayout(bxltx);
c3.setLayout(bxltx);
c4.setLayout(bxltx);
c5.setLayout(bxltx);
c6.setLayout(bxltx);
c7.setLayout(bxltx);
c8.setLayout(bxltx);
c9.setLayout(bxltx);
echedatelbl = new Label("Date d'échéance");
echedatelbl.setUIID("FicheLibelle");
echedatetxt = new TextField();
echedatetxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(echedatetxt, vkNombre);
montantlbl = new Label("Montant(Ar)");
montantlbl.setUIID("FicheLibelle");
montanttxt = new TextField();
montanttxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(montanttxt, vkNombre);
eche_payelbl = new Label("Payé (Ar)");
eche_payelbl.setUIID("FicheLibelle");
eche_payetxt = new TextField();
eche_payetxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(eche_payetxt, vkNombre);
eche_retardlbl = new Label("Retard");
eche_retardlbl.setUIID("FicheLibelle");
eche_retardtxt = new TextField();
eche_retardtxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(eche_retardtxt, vkNombre);
ecehe_nbretardlbl = new Label("Nombre de retard");
ecehe_nbretardlbl.setUIID("FicheLibelle");
ecehe_nbretardtxt = new TextField();
ecehe_nbretardtxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(ecehe_nbretardtxt, vkNombre);
eche_crdlbl = new Label("Crédit (Ar)");
eche_crdlbl.setUIID("FicheLibelle");
eche_crdtxt = new TextField();
eche_crdtxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(eche_crdtxt, vkNombre);
eche_rembourselbl = new Label("Remboursé (Ar)");
eche_rembourselbl.setUIID("FicheLibelle");
eche_remboursetxt = new TextField();
eche_remboursetxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(eche_remboursetxt, vkNombre);
eche_interetlbl = new Label("Intérêt (Ar)");
eche_interetlbl.setUIID("FicheLibelle");
eche_interettxt = new TextField();
eche_interettxt.addDataChangeListener(this);
VirtualKeyboard.bindVirtualKeyboard(eche_interettxt, vkNombre);
flagPayelbl = new Label("Payé");
flagPayelbl.setUIID("FicheLibelle");
flagPayetxt = new ListBox(new String[]{"oui","non","aaaaaa","bbbb"},echedatetxt.getPreferredH(),getPreferredW(),getPreferredH(),eche_interettxt.getSelectedStyle().getMargin(Component.TOP),eche_interettxt.getSelectedStyle().getMargin(Component.BOTTOM));
c10.getStyle().setPadding(Component.LEFT, 0);
c10.getStyle().setPadding(Component.RIGHT, 0);
reset = new Button("Rétablir les données");
reset.addActionListener(this);
reset.getUnselectedStyle().setMargin(0, 0, 0, 0);
reset.getSelectedStyle().setMargin(0, 0, 0, 0);
reset.setAlignment(Label.CENTER);
reset.setUIID("btnDetailCreditFieldset");
c10.addComponent(reset);
modifierBtn = new Button("Valider");
modifierBtn.addActionListener(this);
modifierBtn.getUnselectedStyle().setMargin(0, 0, 0, 0);
modifierBtn.getSelectedStyle().setMargin(0, 0, 0, 0);
modifierBtn.setAlignment(Label.CENTER);
modifierBtn.setUIID("btnDetailCreditFieldset");
c1.addComponent(echedatelbl);
c1.addComponent(echedatetxt);
c2.addComponent(montantlbl);
c2.addComponent(montanttxt);
c3.addComponent(eche_payelbl);
c3.addComponent(eche_payetxt);
c4.addComponent(eche_retardlbl);
c4.addComponent(eche_retardtxt);
c5.addComponent(ecehe_nbretardlbl);
c5.addComponent(ecehe_nbretardtxt);
c6.addComponent(eche_crdlbl);
c6.addComponent(eche_crdtxt);
c7.addComponent(eche_rembourselbl);
c7.addComponent(eche_remboursetxt);
c8.addComponent(eche_interetlbl);
c8.addComponent(eche_interettxt);
c9.addComponent(flagPayelbl);
c9.addComponent(flagPayetxt);
cz1.addComponent(t1);
cz2.addComponent(t2);
cz3.addComponent(t3);
cz4.addComponent(t4);
cz5.addComponent(t5);
int[] labelW = new int[]{echedatelbl.getPreferredW(), montantlbl.getPreferredW(), eche_payelbl.getPreferredW(), eche_retardlbl.getPreferredW(), ecehe_nbretardlbl.getPreferredW(), eche_crdlbl.getPreferredW(), eche_rembourselbl.getPreferredW(), eche_interetlbl.getPreferredW(),flagPayelbl.getPreferredW()};
int largeW = Comparator.max(labelW);
echedatelbl.setPreferredW(largeW);
montantlbl.setPreferredW(largeW);
eche_payelbl.setPreferredW(largeW);
eche_retardlbl.setPreferredW(largeW);
ecehe_nbretardlbl.setPreferredW(largeW);
eche_crdlbl.setPreferredW(largeW);
eche_rembourselbl.setPreferredW(largeW);
eche_interetlbl.setPreferredW(largeW);
flagPayelbl.setPreferredW(largeW+2);
c10.addComponent(modifierBtn);
c.addComponent(c1);
c.addComponent(c2);
c.addComponent(c3);
c.addComponent(c4);
c.addComponent(c5);
c.addComponent(c6);
c.addComponent(c7);
c.addComponent(c8);
c.addComponent(cz1);
c.addComponent(cz2);
c.addComponent(cz3);
c.addComponent(cz4);
c.addComponent(cz5);
c.addComponent(c9);
c.addComponent(c10);
cntnr.addComponent(c);
this.setScrollableY(true);
this.addComponent(cntnr);
echedatetxt.setText(listecheance.elementAt(0).toString());
montanttxt.setText(listecheance.elementAt(1).toString());
eche_payetxt.setText(listecheance.elementAt(6).toString());
eche_retardtxt.setText(listecheance.elementAt(7).toString());
ecehe_nbretardtxt.setText(listecheance.elementAt(8).toString());
eche_crdtxt.setText(listecheance.elementAt(9).toString());
eche_remboursetxt.setText(listecheance.elementAt(10).toString());
eche_interettxt.setText(listecheance.elementAt(11).toString());
textFieldStatus = "NORMAL";
if (String.valueOf(listecheance.elementAt(2)).toLowerCase().startsWith("o"))
flagPayetxt.setSelectedIndex(0);
else if (String.valueOf(listecheance.elementAt(2)).toLowerCase().startsWith("n"))
flagPayetxt.setSelectedIndex(1);
listeMenu = new Command("Liste");
listeClientCmd = new Command("Clients");
listeCreditCmd = new Command("Crédits");
ppalCmd = new Command("Menu principal");
ficheMenu = new Command("Fiche");
backCmd = new Command("Retour");
annulerCmd = new Command("Annuler");
isMenuShown = false;
this.addCommand(listeMenu);
this.addCommand(ficheMenu);
this.addCommandListener(this);
} // end of constructor
...
}
You see that I have considered the two cases if there is space or not below the ListBox in the pointerPressed method of the ListBox class.
When I don't write in the calling Form's code the addComponent for the containers cz1 through cz5 then the Dialog is shown very well below the ListBox component.
So why doesn't the Dialog show when there is no more space at the bottom ?
You invoke the dialog show method with sizes that don't leave any space for the dialog. You need to check that height - top - bottom > dialogPreferreHeight and the same should apply for width.
See the combo box popup code where we conditionally popup the dialog upwards if there is no room bellow.

Resources