Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
cKeys.Keyboard = new KeyboardButton[][]
{

new KeyboardButton[]
{
new KeyboardButton("لیست تعرفه ها"),
new KeyboardButton("تماس با ما"),
new KeyboardButton("نماینده ها")
},

new KeyboardButton[]
{
new KeyboardButton("راهنما")
}
};

What I have tried:

how do i add items with a loop or for ?
Posted
Updated 26-Aug-16 3:23am

You need a list.

List<keyboardbutton> keys = new KeyboardButton<keyboardbutton>();

foreach(item in items)
{
keys.Add(item);
}

//So if you already filled the list of keys, then you can use ToArray() for the list object

cKeys.Keyboard = keys.ToArry();
 
Share this answer
 
Comments
kylix_st1981 26-Aug-16 8:48am    
List<keyboardbutton>[,] keys = new List<keyboardbutton>[2, 1];

keys[0, 0] = new List<keyboardbutton> { "One" };
keys[1, 0] = new List<keyboardbutton> { "two" };
cKeys.Keyboard = keys;


Error :
convert type 'System.Collections.Generic.List<telegram.bot.types.keyboardbutton>[*,*]' to 'Telegram.Bot.Types.KeyboardButton[][]' TelegramRobot
---------------------------------------------------------------------
KeyboardButton[] keys = new KeyboardButton[4];
for (int i = 0; i < keys.Length; i++)
{
keys[i] = new KeyboardButton();
}

cKeys.Keyboard = keys;

Error :
Cannot implicitly convert type 'Telegram.Bot.Types.KeyboardButton[]' to 'Telegram.Bot.Types.KeyboardButton[][]
Simple array can help you as well.

C#
KeyboardButton[] keys = new KeyboardButton[4];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new KeyboardButton();
            }
 
Share this answer
 
Comments
kylix_st1981 26-Aug-16 8:48am    
List<keyboardbutton>[,] keys = new List<keyboardbutton>[2, 1];

keys[0, 0] = new List<keyboardbutton> { "One" };
keys[1, 0] = new List<keyboardbutton> { "two" };
cKeys.Keyboard = keys;


Error :
convert type 'System.Collections.Generic.List<telegram.bot.types.keyboardbutton>[*,*]' to 'Telegram.Bot.Types.KeyboardButton[][]' TelegramRobot
---------------------------------------------------------------------
KeyboardButton[] keys = new KeyboardButton[4];
for (int i = 0; i < keys.Length; i++)
{
keys[i] = new KeyboardButton();
}

cKeys.Keyboard = keys;

Error :
Cannot implicitly convert type 'Telegram.Bot.Types.KeyboardButton[]' to 'Telegram.Bot.Types.KeyboardButton[][]
charmyvora 27-Aug-16 12:14pm    
I just mentioned to use simple array. let me know if you face problem in that
i get this errors

C#
  List<KeyboardButton>[,] keys = new List<KeyboardButton>[2, 1];

            keys[0, 0] = new List<KeyboardButton> { "One" };
            keys[1, 0] = new List<KeyboardButton> { "two" };
            cKeys.Keyboard = keys;


Error : 
convert type 'System.Collections.Generic.List<Telegram.Bot.Types.KeyboardButton>[*,*]' to 'Telegram.Bot.Types.KeyboardButton[][]'	TelegramRobot
---------------------------------------------------------------------
KeyboardButton[] keys = new KeyboardButton[4];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new KeyboardButton();
            }

            cKeys.Keyboard = keys;

Error : 
Cannot implicitly convert type 'Telegram.Bot.Types.KeyboardButton[]' to 'Telegram.Bot.Types.KeyboardButton[][]
 
Share this answer
 
Comments
Patrice T 26-Aug-16 7:24am    
this is not a solution.
Use Improve question to update your question.
woooooooooooooooow
i found the solution
it is like this and work great


C#
KeyboardButton[][] arr = new KeyboardButton[2][];

arr[0] = new KeyboardButton[2];
arr[0][0] = new KeyboardButton("saeed");
arr[0][1] = new KeyboardButton("majid");

arr[1] = new KeyboardButton[1];
arr[1][0] = new KeyboardButton("mehdi");
cKeys.Keyboard = arr;
 
Share this answer
 
i can now
C#
 use it with a

for o loop
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900